Search Unity

scene not restarted

Discussion in 'Scripting' started by CodeWurm, Mar 14, 2019.

  1. CodeWurm

    CodeWurm

    Joined:
    Nov 8, 2014
    Posts:
    316
    After my timer hits 0, I go to the game over screen. When you click on game over I want to restart my game scene. But the weird thing is when I again click on play in my game scene, my timer is doubled, which means that that scene never truly restarted, I guess.

    The weird thing is my scene starts with 10 goes to zero, shows game over, then when I click on game over and click on taptobegin my scene starts with 40 seconds in timer.

    taptobegin triggers loadlevel.
    in menu quit button triggers quitlevel.
    when score is zero onclick gameover button it triggers restartlevel.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class MenuScript : MonoBehaviour
    5. {
    6.     public void Loadlevel()
    7.     {
    8.         SceneManager.LoadScene("test");    
    9.     }
    10.  
    11.     public void QuitLevel()
    12.     {
    13.         Application.Quit();
    14.     }
    15.  
    16.     public void RestartLevel()
    17.     {
    18.         SceneManager.LoadScene("test");
    19.     }
    20. }
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Could have to do with some object that's been set to DontDestroyOnLoad, but I would start by taking a closer look at the timer and how it gets initialized.
     
  3. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    227
    Looks fine to me. I think the problem is on your other script.