Using Enum With Different Scrits

Hello Everyone
I want to use Enums. But i want to ask a help about one thing.
Think that we have 3 Scripts;
One For Enums.

public enum GameState
{
    Run,
    None
};

Second is for time increment and when time is 10 i want Enum equals one of the enum states.

public class ScriptTwo : MonoBehaviour
{
    float timer;
    GameState gameState;
    public void Update()
    {
         timer += Time.deltaTime;
        if (timer>=10)
        {
            gameState = GameState.Run;
        }
    }
}

Third is for using that state for another if condition function in that Script.

public class ScriptThird : MonoBehaviour
{   
    GameState gameState;
    public void Update()
    {
        if (gameState==GameState.Run)
        {
            //do Something
        }
    }
}

How can i make that Scenario? Should Enums be Static or Something?

Currently both script two and script third have their own variable of the GameState type. If you want script three to use script twos gamestate, you would need a ScriptTwo variable in ScriptThird. You can set the value of this variable in the inspector, or using GetComponent. Script twos gamestate would also have to be public. Then accessing script twos gamestate in script third would be something like ScriptTwoVariableName.gameState

@pmurph03 is basically right but i’d suggest a different solution:

Something like a gamestate could be handeled with a public static variable.

So you could have a class like this to handle all this:

public class GameStateHandler{
	public static GameState currentGameState = GameState.None;
}

Then you can use GameStateHandler.currentGameState to access it from anywhere.

Be caseful at this as static variables are carried over when loading scenes!

Also note that this class is not a Monobehaviour. There is no need to add it as a script somewhere, but it also will not have a Start/Awake/Update function access by itself.

EDIT:

I can only strongly suggest to have a “None” enum value to always be the first value in your enum as this will be the value that a new variable of this type will default to.