I’m using an enum defined in a GlobalController class to keep track of which objects are stored in which position in a builtin array. This function was working under JS, but now that it’s been converted to C#, I am getting the following error:
“Constant value 0' cannot be converted to a
int’”
currentChassis = biplane.currentComponents[GlobalController.Components.CHASSIS];
You need to cast the enum to an int.
currentChassis = biplane.currentComponents[(int)GlobalController.Components.CHASSIS];
I’m trying to do a similar thing you did here. I want to define an enum in a global class but I’m not really sure how to do that in Unity. Does my script need be attached to an empty game object in the scene then referenced from the scripts that use the enum?
For Example, if I have:
public class _csEnums : MonoBehaviour {
public enum LineOwner
{
Player,
Tourist0,
Tourist1
};
}
Do I need to attach this script to a game object in the scene? Once this script is active, how do I then access this Enum from other scripts.
For example:
public class _csNewBehavior : MonoBehaviour {
LineOwner owner;
void Start()
{
owner = LineOwner.Player
}
}
It seems it is as easy as referencing the file.
_csEnums.LineOwner owner;
and
owner = _CsEnums.LineOwner.PLAYER;