Creating a Restart Button

Hi, I’m new to Unity, so I don’t know much yet, but I’ve been creating a game which is filled with obstacles, and different paths, and you have to roll the ball around the whole area to collect Yellow Cubes. I’m trying to figure out how to create a Restart button, so that if the player messes up, or falls out, they can just play again. I haven’t written any type of script for the restart button yet, so everybody’s help is appreciated!
(Currently, if you fall out of the boundaries, or want to restart, you have to close out the whole game, and start it again.)

Hi Mrkrisher,

First create an button UI → Button
Then create an class

C# ex:

    using UnityEngine;
    using UnityEngine.SceneManagement;
    using System.Collections;
    
    public class Restart : MonoBehaviour {
    
    	public void RestartGame() {
    		SceneManager.LoadScene(SceneManager.GetActiveScene().name); // loads current scene
    	}
    
    }

attatch this class to a GameObject and drag it in the Button → OnClick component
Select → Restart->RestartGame

And your scene will restart.

Hope this helps for you

NOTE: In case you are using unity 5.3 or less use Application.LoadLevel(Application.loadedLevel); instead of SceneManager.LoadScene(Application.loadedLevel);

Hi! If anyone has problems with timeScale, after restarting. You should add Time.timeScale = 1f; after that so it will return back to normal timeScale. For Example in my game when user dies time will be paused and if i just only did restart it was still paused.

Use That Is More Easier

SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex);

For Reastart