- Home /
Question by
Inblinder · Feb 14, 2018 at 02:31 PM ·
c#scripting problemcanvasrestart
Restarting or going in menu after finishing the game problem.
So :D im again here... Today's problem is that if i "finish my game it sends me to CanvasGroup GameOver or smth like that.. and there i have two buttons, one takes me to menu, one restarts the game. The buttons work well:
public void RestartButton1 ()
{
TurnOffGameOver();
TurnOffInGamePause();
TurnOnInGame();
GameStarted = true;
Time.timeScale = 1;
Score = 0;
ScoreText.text = Score.ToString();
//RESET SPAWNERS
GameObject[] stars = GameObject.FindGameObjectsWithTag("Star");
foreach(GameObject star in stars)
GameObject.Destroy(star);
}
public void MenuButton ()
{
TurnOnMenu();
TurnOffGameOver();
TurnOffInGamePause();
GameStarted = false;
Time.timeScale = 1;
Score = 0;
ScoreText.text = Score.ToString();
GameObject[] stars = GameObject.FindGameObjectsWithTag("Star");
foreach(GameObject star in stars)
GameObject.Destroy(star);
}
= They take me to menu or restarts the game.... BUT i need to click on them like 20 times and than they work perfectly. I AM SO CONFUSED right know. Does anyone know what this occures?
Comment
In fixedUpdate:`if (Lifes == 0) { StartCoroutine(GameOver()); }
IEnumerator GameOver ()
{
GameStarted = false;
GameObject[] stars = GameObject.FindGameObjectsWithTag("Star");
foreach(GameObject star in stars)
GameObject.Destroy(star);
myCameraShake.shakeDuration = 1f / 1.5f;
myCameraShake.shakeAmount = 0.7f;
yield return new WaitForSeconds(1f / 1.5f);
Time.timeScale = 0;
//CANVASGROUPS
TurnOffInGame();
myRotateScript.ScaleBack();
TurnOnGameOver();
Lifes = 5;
myCameraShake.shakeDuration = 0f;
}`