Disable or hide GUI Buttons on one scene
HI. In one scene in my game there is a boss that you cannot defeat. After a couple of seconds you will be taken to the next scene. The problem is that "Retry" and "Back to menu" pops up right after you die and I don't want to player to click one of them (because they will miss out on the next scene). Does anyone know how to disable or hide them for just this scene and not the others. The scenes I have are: Menu, Stage 1, Stage 2, Stage 3 (where I need them to be gone) and Stage 4. Thank you!
Here is the Game Over script where the GUI Buttons are:
public class GameOverScript : MonoBehaviour
{
void OnGUI()
{
const int buttonWidth = 120;
const int buttonHeight = 60;
if (
GUI.Button(
// Center in X, 1/3 of the height in Y
new Rect(
Screen.width / 2 - (buttonWidth / 2),
(1 * Screen.height / 3) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"Retry!"
)
)
{
// Reload the level
Application.LoadLevel("Stage 1");
}
if (
GUI.Button(
// Center in X, 2/3 of the height in Y
new Rect(
Screen.width / 2 - (buttonWidth / 2),
(2 * Screen.height / 3) - (buttonHeight / 2),
buttonWidth,
buttonHeight
),
"Back to menu"
)
)
{
// Reload the level
Application.LoadLevel("Menu");
}
}
}
Comment
Answer by hexagonius · Jan 15, 2016 at 11:35 AM
Check forif (Application.loadedLevelName == "desired Level") return;