I’ve spent most of the day( unbeknownst to my boss :p) googling for answers,…which I found some that sound good,…but doesn’t seem to work when I apply it.
My situation (simplified example)
Instantiate 3 cubes, each with two scripts, EnumScript and PassValue, on the same object.
EnumScript
public class EnumScript : MonoBehaviour {
public enum PlayerState{offense,defense,neutral}
public PlayerState statusP;
void Start () {
statusP = PlayerState.neutral;
}
void OnMouseOver()
{
Debug.Log("State ==== " + statusP); // checking to see if anything changed
}
PassValue
public class PassValue : MonoBehaviour {
void Start () {
}
void OnMouseDown()
{
EnumScript enumScript;
enumScript = GetComponent<EnumScript>();
//enumScript.statusP = PlayerState.defense; // fail
EnumScript.PlayerState statusP = EnumScript.PlayerState.defense; // trying to change the enum
}
I want each cube to have it’s own enum state(offense,defense,neutral) when I click it,…and not be global across all of them.
Which I can get to work fine IF I change it within it’s own Class, for example. I can also pass other variables like Bool and INT no problem.,.it’s just enums are being a pain.
Currently, the above script does Nothing,…no errors ,…just nothing but debug it’s default state(neutral) on MouseOver.
If anyone has a solution to apply to this example, I’d be very appreciative!
Also…while we’re talking about Enums,…do they play nice as a Singleton? ![]()
THANKS!
-Welby