Using Enum across several files

Let say that I have the following enum coded in a file.

public class EnumList : ScriptableObject {
 
 public enum E_COLORS { RAINBOW, RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET, LENGTH };
 public enum E_NUMBERS { INF, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, LENGTH };
 
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }
}

How can I gain access to this from a different script file?

You need to use EnumList.E_COLORS etc.

You can just write:

EnumList.E_COLORS

Or if you wanted a class that has one of those colours:

public class myNewClass : MonoBehaviour
{
private EnumList.E_COLORS _color = EnumList.E_COLORS.RED;
}

Hope this helps. I have done it a number of times myself.

You don’t need Scriptable Object to create enums. Just move the enums outside of any class in any script file you like. And they will be available in all scripts.

Don’t forget to make them public though.