So i am trying to make a restart button, but there seems to a problem. My script: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Restart : MonoBehaviour { public void RestartGame() { public scene = SceneManager.LoadScene("2D Space Shooter"); } } And the unity interface with the console errors and inspector: https://imgur.com/a/Oek2Qfy Thanks!
public scene = SceneManager.LoadScene("2D Space Shooter"); This bit of code doesn't fully make sense as defined. When defining a local variable, you need to give the variable a Type, and you can't declare something "public" inside a function. Also, the "LoadScene" method doesn't return a value, so you can't assign it to a variable anyway. So get rid of "public scene =" and it will probalby work.
Yeah don't worry i fixed that one: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Restart : MonoBehaviour { void OnGUI() { if(GUI.Button(new Rect(269, 10, 75, 30), "Restart")) { SceneManager.UnloadSceneAsync("2D Space Shooter"); SceneManager.LoadScene("2D Space Shooter"); } } } I removed the public scene, but then it still didn't work so i created a button. But then when i clicked that it just repeated what was on screen anyway. So i had to unload the scene then load it again.