Hello all,

So I am trying to use an Enum in my project called GameType. It essentially lets my scripts know that the GameType is X that so they can preform logic based on what GameType it is.

Now, I know that Enums dont need to be accessed through GetComponent, but I have a few questions.

First - Can I assume that if the script in which the Enum is located doesnt exist yet in the game, I am going to run into problems right? For example, in my main menu, If you click on GameType X, I want to set the Enum GameType to X, but if my GameType Enum is located in a script that doesnt really exist until a level is loaded - that isnt going to work right? Or does it just have to exist somewhere in the project file in unity and all is golden?

Next question: I am having a heck of a time just changing the values of an Enum. I must have some syntax wrong somewhere but I am a bit confused here:

Code for the Enum (its outside the class right now but I have tried in a class and outside a class):

	public enum GameType						
	{												
		SoloCompetitive,
		TeamCompetitive,
		OpenPlay		
	}

Now here is an example when I am trying to change the enum:

if(GUI.Button(new Rect(teamCompetitive),"Team Competitive"))
		{
			audio.PlayOneShot(beep);
			GameType = GameType.TeamCompetitive;
		}

But I get the error: The left-hand side of an assignment must be a variable, a property or an indexer.

Thanks in advance guys!

As the error says, the left side has to be a variable. GameType is an enum; you can’t assign values to an enum. Make a variable of type GameType and assign a value to that variable instead.

Enums are global and don’t need to exist in a script that’s in the scene.

If the script is in the project, you can access anything in it. With your enum, you need to create a variable for it. You can’t just set the enum itself.

    public enum GameType               
    {                              
       SoloCompetitive, // 0
       TeamCompetitive, // 1
       OpenPlay   // 2
    };

    GameType theGameType = GameType.OpenPlay;