Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Press Start

Discussion in 'Scripting' started by BoxTraininc, Jan 22, 2022.

  1. BoxTraininc

    BoxTraininc

    Joined:
    Mar 11, 2020
    Posts:
    64
    I need help with a working Title Screen. Supposedly, you'll need to press Enter to start the game, but I don't know 2 things

    - What the Keycode is for Enter in Unity (I tried return, it didn't work)
    - How to change scene in Unity, I know I need to use the Unity SceneManagement but it's not working

    I've looked for some basic tutorials, but none of them really helped.

    Code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6.  
    7. public class MainMenu : MonoBehaviour
    8. {
    9.     public void PlayGame()
    10.     {
    11.         if (Input.GetKeyDown(KeyCode.Enter))
    12.         {
    13.             SceneManager.LoadScene(1);
    14.         }
    15.     }
    16. }
     
  2. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    Enter IS return. Maybe double check your inputs and see if it's actually listed in there... If not, add it in. Find it in Edit>ProjectSettings>InputManager.

    As for changing the scene, you need to use SceneManager.LoadScene.
    Don't forget to go into File>Build Settings and add the scene to the list via 'Add Open Scenes'
     
  3. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    question is where do you execute PlayGame() it's not on Update() or FixedUpdate() on your script.
     
    ZO5KmUG6R and knobblez like this.