private void GameOver() { if (!gameOver) { //Turn on win message - player 1 win message must be first child of canvas. int childIndex = gameObject.tag == "Player1" ? 0 : 1; GameObject child = canvas.transform.GetChild(childIndex).gameObject; child.gameObject.GetComponent <Image>().enabled = true; //=============================================================================================// if (this.gameOverSound != null) { this.gameOverSound.Play(); } if (this.fightMusic != null) { this.fightMusic.Stop(); } gameOverTime = Time.time; gameOver = true; enemyScript.SetGameOver(true); } else if (gameOver && Time.time > gameOverTime + gameOverWait) { //restart the current scene DataStore.ready = false; if (DataStore.p1Wins >= 3 || DataStore.p2Wins >= 3) { DataStore.p1Wins = 0; DataStore.p2Wins = 0; endMenu.SetActive(true); } else { if (this.fightMusic != null) { this.fightMusic.PlayDelayed(2.0f); } SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } else if (!won) { GameObject ChildGameObject = this.gameObject.transform.GetChild(1).gameObject; ChildGameObject.GetComponent <SpriteRenderer>().enabled = false; } }
private void GameOver() { if (!gameOver) { //Turn on win message - not working //GameObject child = canvas.transform.GetChild(1).gameObject; //child.gameObject.GetComponent<Text>().enabled = true; gameOverTime = Time.time; gameOver = true; enemyScript.SetGameOver(true); } else if (gameOver && Time.time > gameOverTime + gameOverWait) { SceneManager.LoadScene("FinalMainScene", LoadSceneMode.Single); } else if (!won) { GameObject ChildGameObject = this.gameObject.transform.GetChild(1).gameObject; ChildGameObject.GetComponent <SpriteRenderer>().enabled = false; } }