using UnityEngine;
public class RestartGame : MonoBehaviour
public void Button_Click()
{
Application.LoadLevel(Application.loadedLevel)
}
//Don’t working
using UnityEngine;
public class RestartGame : MonoBehaviour
public void Button_Click()
{
Application.LoadLevel(Application.loadedLevel)
}
//Don’t working
Maybe instead try sceneManager.LoadScene(“whatever scene you want to restart at”) ?
Application.LoadLevel and Application.loadedLevel are deprecated. It has been replaced with the new features in UnityEngine.SceneManagement.
Try this:
using UnityEngine;
using UnityEngine.SceneManagement;
public class RestartGame : MonoBehaviour
{
public void Button_Click()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
‘sceneManager.LoadScene does not exist in current context’
Working
but if I restart game my shaders does not working ![]()
Pro tip (assuming you’re using visual studio), if you mouse over the error, it’ll suggest fixes, in this case you could of clicked on the first suggestion and it would’ve added the using directive in for you, just something that’s worth knowing! ![]()
thanks @Tovey-Ansell
its SceneManager.LoadScene(SceneManager.GetActiveScene(“YourSceneName”).name);
Ok maybe not…
ADD THIS LINE! using UnityEngine.SceneManagement;
using UnityEngine.SceneManagement;
public class QToRestart : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown ("space")) {
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}```
This is not working.