TowerDefens: After retry the game freeze

Updated on March 28, 2017 in [A] Tutorials
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
4 on March 22, 2017

Hello,

I just completed the TowerDefens tutorial. But i have a problem. Every time i press the retry button the game freezes. I compared my code with the code i could find on gidhub but I couldn’t find the problem. Does someone know how I can fix this?

Thx

  • Liked by
Reply
0 on March 23, 2017

You might get more help if you post the contents of your GameManager and GameOver scripts.

  • Liked by
Reply
Cancel
1 on March 26, 2017

Hello,

Oké this is what i have:

Pausemenu

using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour {
 public GameObject ui;
 public string menuSceneName = "MainMenu";
 public SceneFader sceneFader;
 void Update ()
 {
 if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.P))
 {
 Toggle();
 } 
 }
 public void Toggle()
 {
 ui.SetActive(!ui.activeSelf);
 if (ui.activeSelf)
 {
 Time.timeScale = 0f;
 }
 else
 {
 Time.timeScale = 1f;
 }
 }
 public void Retry()
 {
 Toggle();
 sceneFader.FadeTo(SceneManager.GetActiveScene().name);
 }
 public void Menu()
 {
 Toggle();
 sceneFader.FadeTo(menuSceneName);
 }
}

GameManager:

using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
 public static bool GameIsOver;
 public GameObject gameOverUI;
 public GameObject completeLevelUI;
 void Start ()
 {
 GameIsOver = false;
 }
 void Update ()
 {
 if (GameIsOver)
 return;
 if (PlayerStats.Lives <= 0)
 {
 EndGame();
 }
 }
 void EndGame ()
 {
 GameIsOver = true;
 gameOverUI.SetActive(true);
 }
 public void LevelWon()
 {
 GameIsOver = true;
 completeLevelUI.SetActive(true);
 }
}

GameOver:

public class GameOver : MonoBehaviour {
 public string menuSceneName = "MainMenu";
 public SceneFader sceneFader;
 public void Retry ()
 {
 sceneFader.FadeTo(SceneManager.GetActiveScene().name);
 }
 public void Menu ()
 {
 sceneFader.FadeTo(menuSceneName);
 }
}

It’s really weird because the continue and menu button work just fine. But when i do: esc -> menu (in pause screen) -> play (in menu screen) -> select a level (in levelselect screen) then also the level is frozen.

Does someone know what is wrong?

on March 26, 2017

I think it’s not the game is frozen after the retry, but the waves will not spawn.
When i start the game normal i get the 2 second countdown before the first wave spawns. but when i restart the timer is already 0 and the wave will not spawn. Can’t it be that thats the problem? 

How can i solve this problem?

Show more replies
  • Liked by
Reply
Cancel
0 on March 28, 2017

Does someone have an idee how I can fix this?

  • Liked by
Reply
Cancel