- Home /
Stack Overflow Exception & Importing Images So They Can Be Scripted
I'm working on a basic 2D menu system utilizing three scenes for each menu. However, when I actually change scenes I get a Stack Overflow Exception error. What am I doing wrong? Also, I'm having trouble importing image assets to use as a backgrounds and icons. How do I do this as well. For the first problem here's the scripting code in C#:
public class FScript : MonoBehaviour
{
// Variables
public int sceneIndex = 0;
public bool escapeCheck = false;
// Use this for initialization
void Start ()
{
MainMenu();
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
escapeCheck = !escapeCheck;
}
void OnGUI()
{
if (!escapeCheck)
{
if (sceneIndex == 0)
MainMenu();
else if (sceneIndex == 1)
GameScene();
else if (sceneIndex == 2)
TestScene();
}
else
showDialog();
}
void MainMenu()
{
if (GUI.Button(new Rect(150, 150, 100, 100), "START"))
{
sceneIndex = 1;
SceneLoader();
}
if (GUI.Button(new Rect(270, 150, 100, 100), "TEST"))
{
sceneIndex = 2;
SceneLoader();
}
if (GUI.Button(new Rect(390, 150, 100, 100), "QUIT"))
Application.Quit();
}
void GameScene()
{
GUI.Label(new Rect(Screen.width - (Screen.width / 2), Screen.height - (Screen.height / 2), 100, 100), "GAME SCENE");
if (GUI.Button(new Rect(10, Screen.height - 280, 270, 270), "BACK"))
SceneLoader();
OnGUI();
}
void TestScene()
{
GUI.Label(new Rect(Screen.width - (Screen.width / 2), Screen.height - (Screen.height / 2), 100, 100), "TEST SCENE");
if (GUI.Button(new Rect(10, Screen.height - 280, 270, 270), "BACK"))
SceneLoader();
OnGUI();
}
void showDialog()
{
GUI.BeginGroup(new Rect(Screen.width - (Screen.width / 2) - 100, Screen.height - (Screen.height / 2) - 100, 300, 300), "Do you want to return to the main menu?");
if (GUI.Button(new Rect(1, 100, 90, 55), "YES"))
{
sceneIndex = 0;
escapeCheck = false;
SceneLoader();
OnGUI();
}
if (GUI.Button(new Rect(150, 100, 90, 55), "NO"))
escapeCheck = false;
GUI.EndGroup();
}
void SceneLoader()
{
if (sceneIndex == 0)
Application.LoadLevel("MainMenu");
else if (sceneIndex == 1)
Application.LoadLevel("GameScene");
else if (sceneIndex == 2)
Application.LoadLevel("TestScene");
}
}
Comment
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Switch Between GUI images 0 Answers
Bigger size button help 2 Answers
Level select design approaches. 0 Answers