/// <summary> /// Runs on controller creation. /// </summary> private void Awake() { // If the object has not been set yet (this object) if (canvas == null) { // Don't EVER destroy this one, and set this object so we have a reference to it later. DontDestroyOnLoad(gameObject); canvas = this; // Reassign the button onClick methods Button[] buttons = this.gameObject.GetComponentsInChildren <Button>(); foreach (Button b in buttons) { if (b.name == "ButtonResume") { b.onClick.AddListener(LocalResume); } if (b.name == "ButtonMainMenu") { b.onClick.AddListener(LocalNavigation_Title); } if (b.name == "ButtonQuit") { b.onClick.AddListener(LocalNavigation_Quit); } } } else if (canvas != this) { // If there is an object already stored, and it's not this one, destroy this! Destroy(gameObject); } }
void Update() { if (GameState.State == GameState.States.PLAY || GameState.State == GameState.States.PAUSE) { if (Input.GetKeyDown(KeyCode.Escape)) { if (GameState.State == GameState.States.PLAY) { GameState.State = GameState.States.PAUSE; Time.timeScale = 0.0f; } else { GameState.State = GameState.States.PLAY; Time.timeScale = 1.0f; } CanvasPause.SetActive(!CanvasPause.activeSelf); } } }