- Home /
How to restart the game
I am looking for a way that I can restart the game with pressing the letter R without closing out of the application in standalone. I only have 1 scene and I have NO Experience. Please help me:D
@doublemax Alright... It does not really make sense. IS there any way I could make the scene restart when my character (Skycar) hits a plane?
Answer by doublemax · Oct 09, 2016 at 07:52 AM
using UnityEngine.SceneManagement;
SceneManager.LoadScene( SceneManager.GetActiveScene().name );
this doesn't work when you have objects marked as dontdestroyonload
Answer by LiamDietrich · Oct 09, 2016 at 03:24 PM
@doublemax where do you put this line on code?
Save this as "Restart.cs" and add it to any component that's always active, e.g. the main Camera or a Game$$anonymous$$anager object if you have something like that.
using UnityEngine;
using UnityEngine.Scene$$anonymous$$anagement;
public class Restart : $$anonymous$$onoBehaviour
{
void Update ()
{
if( Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R) )
{
Scene$$anonymous$$anager.LoadScene( Scene$$anonymous$$anager.GetActiveScene().name );
}
}
}
Answer by NikitaDemidov · Dec 31, 2018 at 03:00 PM
using UnityEngine;
public class Restart : MonoBehaviour {
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
Application.LoadLevel(0);
}
}
}
Try this!
I believe this should be the proper code in restarting your game as Application.LoadLevel(0);
gets the first scene of your game while the Scene$$anonymous$$anager.GetActiveScene().name
could probably gets the third level of your game which does not totally restart your game but just restarting that level. However the Code is obsolete and rather use Scene$$anonymous$$anager.LoadScene(0);
Answer by cmdbarret · Dec 31, 2018 at 03:39 AM
@doublemax can I ask why this changes the games lighting?
I haven't used Unity for 2 years, but Googling found this: https://answers.unity.com/questions/1264278/unity-5-directional-light-problem-please-help.html