Hello, I wrote a switch statement and used another script to switch it's case, but the switch statement keeps defaulting back to the first case. How can i fix this?
My enum plus the switch statement in the update function. Code (csharp): public enum GameState { MainMenu, CurLevel, GameOver, Score } public GameState gs; // Update is called once per frame void Update () { print ("The gamestate is currently on: " + gs); switch(gs) { case GameState.MainMenu:{ //Debug.Log("Game is currently on the main menu"); break; } case GameState.CurLevel:{ //Debug.Log("Game is currently on level: " + Application.loadedLevelName); GamePaused(); Debug.Log ("Game pausing enabled"); GamePlaying(); //mm.enabled = !mm.enabled; break; } case GameState.GameOver:{ GameRestart(); break; } case GameState.Score:{ break; } } } The code that changes the switch case supposedly. Code (csharp): if (GUI.Button(new Rect(10, 70, 50, 30), "Level 1")) { //Application.LoadLevel(1); Debug.Log("Clicked level 1 button"); gamemanager.instance.gs = gamemanager.GameState.CurLevel; }
I assume it has something to do with how you're referring to the manager script, but you haven't shown how that's set up so I'm not sure. By the way, enums are global (within a namespace) so you can just say GameState.CurLevel, you don't need to qualify it. --Eric
Code (csharp): public Texture btnTexture; public GameObject gamOBJ; private gamemanager gam; // Use this for initialization void Awake () { gam = gamOBJ.GetComponent<gamemanager>(); } this is how i reference the manager script.
A variable doesn't change value all by itself... I have the feeling your got other object accessing it and modifying somewhere else, other than the code snippets you posted.
thank you i will take a look through all of my code, because this should not be happening. I also have a question, when a script is started up, are the variables declared before the awake function?