So, for the game I am making I want to add a main menu. It is kind of mandatory nowadays. So I made a pretty bad looking menu but it works for testing porpoises. I use the “W” and “S” keys to cycle between the “Play” and “Exit” buttons, and “A” and “D” to cycle between levels. Normally I should be able to load the scene when I select the first level but for some reason it doesn’t want to load it. I press “Enter” and nothing happens. Is there any way to fix this?
Menu script:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class MenuScreen : MonoBehaviour {
float originalWidth = 1366.0f;
float originalHeight = 768.0f;
Vector3 scale;
public GUIStyle text, titleText, titleShadow;
public Texture2D bg;
bool playSelect = true, exitSelect = false, play = false, menu = true;
public LevelStore[] levels;
int levelSelectCount = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
inputController ();
}
void inputController ()
{
if (menu == true) {
if (Input.GetKeyDown (KeyCode.S) && playSelect == true || Input.GetKeyDown (KeyCode.W) && playSelect == true) {
exitSelect = true;
playSelect = false;
} else if (Input.GetKeyDown (KeyCode.S) && exitSelect == true || Input.GetKeyDown (KeyCode.W) && exitSelect == true) {
exitSelect = false;
playSelect = true;
}
if (Input.GetKeyDown (KeyCode.Return) && playSelect == true) {
menu = false;
play = true;
} else if (Input.GetKeyDown (KeyCode.Return) && exitSelect == true) {
Application.Quit ();
}
} else if (play == true) {
if (Input.GetKeyDown (KeyCode.Backspace)) {
play = false;
menu = true;
}
if (Input.GetKeyDown (KeyCode.D) && levelSelectCount < levels.Length - 1) {
levelSelectCount++;
}
if (Input.GetKeyDown (KeyCode.A) && levelSelectCount > 0) {
levelSelectCount--;
}
if (Input.GetKeyDown (KeyCode.Return) && levels [levelSelectCount].unlocked == true) {
SceneManager.LoadScene (levels [levelSelectCount].sceneManagerName);
}
}
}
LevelStore script (it is used to load the scene, at least that’s what the guy that made the tutorial I follow said, or maybe I misunderstood him. Correct me if I’m wrong):
using UnityEngine;
using System.Collections;
public class LevelStore : MonoBehaviour {
public string levelName;
public Texture2D levelIcon;
public int hightScore = 0;
public bool unlocked = false;
public string sceneManagerName;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}