繁体   English   中英

如何从 Unity 中的另一个脚本引用枚举

[英]How to reference an enum from another script in Unity

因此,我一直在尝试访问名为“ModulesList”的脚本中的枚举类。 我尝试了以下方法:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ModuleIdentifier : MonoBehaviour
{
    public string CurrentSongModule;
    ModulesList moduleList = new ModulesList();

    // Start is called before the first frame update
    void Start()
    {

    }
}

但它不起作用。 我如何引用这个枚举?

因此,从您的ModuleList类中,我将提供一个示例枚举,因为您没有说明这些枚举是什么

所以让我们说你的枚举在 ModuleList 中是这样的

class ModuleList:MonoBehaviour
{

public enum YourEnum
     {
         None, SampleA, SampleB;
     }

}

那么这就是您从ModuleIdentifier脚本中调用它的ModuleIdentifier

class ModuleIdentifier : MonoBehaviour
{

    ModuleList ML = new ModuleList();
    if(ML.YourEnum == ML.None)
    {
        //do something
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM