- Home /
Having trouble making Level Complete text, GUI appear
I'm trying to create some "Level Complete" text which appears when the player completes all of the objectives of the game. It's supposed to function as follows:
The game pauses
The screen darkens a bit
The text appears
Numerous options (e.g. "replay level", "continue", "main menu") appear underneath text
Game "un-pauses" after player chooses one of the options available
To make this all happen, I'm using a GUIText element as the "Level Complete" text and some GUILayout buttons for the options after beating the level.
Right now, the script handling the above functions is referencing a Boolean variable (from another script)which checks if all objectives have been completed. If this variable holds a value of true, then the GUIText and GUILayout buttons should appear on screen. Here's an example of what I'm trying to do with the GUI elements:
void OnGUI()
{
//start GUI elements as disabled, so they don't show
GUI.enabled = false;
GUI.color = Color.clear;
//using GUILayout for nicer look
GUILayout.BeginArea(new Rect(Screen.width / 2 - guiWidth / 2, Screen.height / 2 - guiHeight / 2, guiWidth, guiHeight));
{
GUILayout.BeginHorizontal();
{
//Time.timeScale = 0;
if (GUILayout.Button("Replay"))
{
//Time.timeScale = 1;
Application.LoadLevel("");
gc.goalComplete = false;
}
if (GUILayout.Button("Continue"))
{
//Time.timeScale = 1;
Application.LoadLevel("");
gc.goalComplete = false;
}
if (GUILayout.Button("Main Menu"))
{
//Time.timeScale = 1;
Application.LoadLevel("MainMenu");
gc.goalComplete = false;
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndArea();
//if all goals are complete, then display GUI elements
if (gc.goalComplete == true) {
GUI.enabled = true;
GUI.color = Color.white;
}
}
Unfortunately, neither the GUIText nor the GUILayout elements are appearing when the Boolean variable is true. Right now, I wanted to ensure the GUI appears properly; the other elements (i.e. pausing the game after the level ends, fading to darker color) can wait.
I'm having exatly the same problem. It seems to work fine if you put the 'void onGUI' into the same script as the one holding the bool, but as soon as I put it into another script (and update the references), nothing works!!!