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

How do you add A reset button?

Discussion in 'Game Design' started by MostLikelyANormalGameDev, Apr 15, 2023.

  1. MostLikelyANormalGameDev

    MostLikelyANormalGameDev

    Joined:
    Apr 15, 2023
    Posts:
    2
    Hi, I'm fairly new to making games, and I don't know how to make code where you press a button and the game resets.
    also, I dont know how to move buttons. they never seem to move for me.

    My Unity version is 2021.3.20f1
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi and welcome,

    I think you can make this kind of setup very complicated, or simple. This depends a lot on your game or software you are trying to make, and the complexity it is going to have.

    In the simplest case you could just reload the scene, if we imagine that everything your game has is set up there. i.e. it could be the players starting position, pickups and enemies positions or whatever you might have. And if you need to store some data permanently, you could do that with PlayerPrefs or such.

    Here's some pseudo code, you need to expand this to real code with a bit more of stuff. But in practice you could use SceneManagement to load the current active scene, when the player presses your reset button.

    Code (CSharp):
    1. using UnityEngine.SceneManagement;
    2. SceneManager.LoadScene(SceneManager.GetActiveScene().name);
     
  3. MostLikelyANormalGameDev

    MostLikelyANormalGameDev

    Joined:
    Apr 15, 2023
    Posts:
    2
    I get what you are trying to say, but I cant find a way to expand this. do you have instructions on how to do this?
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @MostLikelyANormalGameDev it might be a good idea to look into basic C# tutorials, and also Unity tutorials. You really can't avoid programming and C# if you want to make games with Unity?

    Nowadays learning couldn't be easier. There's tons of tutorials on the web, and you could now use ChatGPT as your personal teacher?
     
  5. Rin-Dev

    Rin-Dev

    Joined:
    Jun 24, 2014
    Posts:
    557
    Definitely look up some basic tutorials on youtube that involve Unity.
    Some favorites of mine-
    My advice is do not try to Frankenstein code to make a game. Follow a video from start to finish, exactly how they have it, and see how it works. After that, edit small things here and there out of curiosity and see what changes. If you get an error code, google it and see what others have said about it. A lot of the times, the error code will actually tell you exactly what is wrong and what to fix.

    Experimentation is not bad at all. But for the experiments to be meaningful, you have to have a small understanding of what you're doing.