Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question What is the best way to reset scene without resetting score and buttons?

Discussion in 'Scripting' started by SterbenWarStorm, Jul 8, 2023.

  1. SterbenWarStorm

    SterbenWarStorm

    Joined:
    Jul 8, 2023
    Posts:
    6
    I am trying to make a clicker where the player can die, and when they die I want the score to be lowered by a specific percentage. I am using this code as a placeholder as I develop the other parts of the game that won't need to be preserved


    public void restartGame()
    {
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }


    I currently only have one scene, so if I make a script to keep the score's GameObject, there will be two scores. I will also add buttons for powers and exp/levels.

    What might be the best way to go about doing this? I don't really want these to be brought in in the first scene saying "start game", but if that is the easiest and/or most optimized and overall best option I will 100% do it.

    p.s. I value optimization more than the ease of implementation, but I also value how easy it is since I am just starting out with unity.
     
  2. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    143
    Last edited: Jul 8, 2023
    SterbenWarStorm likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Please use the scripting forum for generic scripting question. This is the 2D forum.

    I'll move your post for you.

    Thanks.
     
  4. SterbenWarStorm

    SterbenWarStorm

    Joined:
    Jul 8, 2023
    Posts:
    6
    Yeah I posted it here because it's a 2D game, but thank you. That is definitely a better place for this question.
     
  5. SterbenWarStorm

    SterbenWarStorm

    Joined:
    Jul 8, 2023
    Posts:
    6
    Thank you so much. I think I will use this method.

    Could you explain how to implement this and what exactly happens when it's used? I am a tad confused.
     
  6. venediklee

    venediklee

    Joined:
    Jul 24, 2017
    Posts:
    143
    Implement what? The static field on a static class? Just google it or ask chatgpt(cautiously, it is confidently wrong about a lot of things)

    There should be some example of the OnApplicationQuit on its documentation page

    If you dont know what to do, follow more tutorials first; make sure to implement the tutorial yourself instead of just watching it
     
    SterbenWarStorm likes this.