0

I'd like the restart-button to work after the game, not only during the game. The button is there (visible) during the game, but it only works during the game. Whenever "gameOn is false, the button stops working. I just learning how to write code, so I'm sorry if this is too obvious.

I've tried to make the RestartGame() an if-statement.

public void GameOver()
      {
       gameOn = false;
       gameOverText.gameObject.SetActive(true);
       restartButton.gameObject.SetActive(true);
      }
public void RestartGame()
      {
       SceneManager.LoadScene(SceneManager.GetActiveScene().name);
      }

It's possible to restart the game during game play, but not after the game is over.

enter image description here

Senseless
  • 99
  • 1
  • 8
  • Is the `RestartGame` method on a script on the restart button itself, or some other object? – DetectivePikachu Nov 07 '19 at 16:26
  • It's on the player as PlayerController.cs – Senseless Nov 07 '19 at 16:37
  • 1
    Do you destroy or deactivate the player when the game ends? If the player doesn't exist or isn't active when the button tries to call the script on the player it wont work. Scene management and stuff should not be attached to the player object. Make an empty game object for this sort of thing. Player should only have functionality specific to the player character itself in its code. Scene management is outside of the scope of what a Player should know about. – DetectivePikachu Nov 07 '19 at 16:41
  • 2
    There is no "mistake" in the provided code so the issue is either generated somewhere else or unfortunately not reproducible without further information. – derHugo Nov 07 '19 at 16:54

0 Answers0