简体   繁体   English

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

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

So, I've been trying to access an enum class in a script called "ModulesList".因此,我一直在尝试访问名为“ModulesList”的脚本中的枚举类。 I've tried the following:我尝试了以下方法:

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()
    {

    }
}

but it doesn't work.但它不起作用。 How can I reference this enum?我如何引用这个枚举?

So from your class ModuleList I'll provide an example enum because you did not state what are those enum因此,从您的ModuleList类中,我将提供一个示例枚举,因为您没有说明这些枚举是什么

So let's say that your enum is in ModuleList like this所以让我们说你的枚举在 ModuleList 中是这样的

class ModuleList:MonoBehaviour
{

public enum YourEnum
     {
         None, SampleA, SampleB;
     }

}

Then this is how you will call it from your ModuleIdentifier script那么这就是您从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