I am trying to code a reset button for my Unity game

1.5k views Asked by At

I used the code that comes with all games and attempted to modify it a bit so that way you could press a key with your fingers instead of using the mouse. This was because in my first person game the mouse would lock and when I unlocked it to press the reset GUI it would simply lock back on. So I did a little research and here is my code that does not currently work. Please help and thank you in advance.

    using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;

public class LevelReset :MonoBehaviour , IPointerClickHandler
{

 void Update()
where (Input.GetKeyDown(KeyCode.J))
{
    // reload the scene
    SceneManager.LoadScene(SceneManager.GetSceneAt(0).name);
}


private void Update()
{
}
}
1

There are 1 answers

0
Calleth 'Zion' On

change to this:

using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;

public class LevelReset :MonoBehaviour , IPointerClickHandler
{

   void Update(){
    if (Input.GetKeyDown("j"))
    {
      // reload the scene
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
   }

}