Reload Current Scene with Scene-manager

Hello, I need helps with the scripting for reloading the current scene.

I know there is already similar discussion and answer about this but it doesn’t work out mine for some reason. I am not expert coding but this should work?

I am making a 3D floating platform game where if you fell out the platform, you hit R key to restart the current scene but the script doesn’t work for some reason;

using UnityEngine;
using System.Collections;

public class reload : MonoBehaviour{
	void Update(){
		if(Input.GetKeyDown(KeyCode.R)){
			Scene scene = SceneManager.GetActiveScene(); SceneManager.LoadScene(scene.name);
		}
	}
}

Can anyone tell me what wrong with these code or me? thanks

I think you’re missing a ‘using’ statement at the top of your script:

using UnityEngine.SceneManagement;

In future, if something’s not working then check the console for errors!

Sorry I’ve tried but still no avail; the code is below;

using UnityEngine.SceneManagement;
using System.Collections;

public class reload : MonoBehaviour{
	void Update(){
		if(Input.GetKeyDown(KeyCode.R)){
			Scene scene = SceneManager.GetActiveScene(); SceneManager.LoadScene(scene.name);
		}
	}
}

The console saying the error is at fourth line, saying “The type or namespace name ‘MonoBehaviour’ could not be found (are you missing a using directive or an assembly reference)”

thanks

An old question but a nicer way to do this is:

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

Or maybe SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); is even nicer since it uses integers instead of strings