How do I restart the scene that I'm currently in, through script in unity 2d so that it resets my sprites?

Viewed 3180

I'm trying to find a script for unity 2d. I need one that restarts the scene I've currently loaded. I've tried a couple from the internet, but none of them seem to work. I just need the basic script, not any way to trigger it because I can do that myself. Thanks in advance!

2 Answers

I would recommend you to go through the SceneManager class in Unity Docs.

However, you can use this line to reload the current scene thus, restarting it:

SceneManager.LoadScene(SceneManager.GetActiveScene());

Hope that answers your questions.

This is what I did:

void Start()
{
    Button Button = this.GetComponent<Button>();
    Button.onClick.AddListener(Reset);
}

public void Reset()
{
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

It only takes in a build index

Related