Continuing to next scene with button by using "Enter key" instead of "Left Click"

I think my code must be pretty close, but I can’t get a keyboard key to take me to the next scene. I have attached the script for the next scene to the button and it is selected in the onclick () area in the inspector tool. My code is as follows:

using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneLoader : MonoBehaviour
{
    public void update()
    {
        {
            if (Input.GetKey(KeyCode.return))
            {
                LoadNextScene();
            }
        }
    }
        public void LoadNextScene()
    {
        int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
        SceneManager.LoadScene(currentSceneIndex + 1);
    }
    public void LoadStartScene()
    {
        SceneManager.LoadScene(0);
        FindObjectOfType<GameSession>().resetScore();
    }
    public void QuitGame()
    {
        Application.Quit();
    }
    }

EDIT: By selecting the update method in the onclick tab I can get the button to carry me to the next scene by first clicking the button and then pressing the keyboard key. How would I eliminate the need for clicking the button initially and therefore, only require me to press the keyboard key?

Your update is lowercase. Case matters. Change it to Update and Unity will autorun it every frame.

2 Likes

I can’t believe my problem was this simple! Thank you!