- Home /
Making an options screen that changes?
So at the moment, my title screen has 3 buttons, Play Game, Options, and Quit Game. I have 2 different levels for the game, but I do not know how to make it so that when the player presses Play Game, all the buttons are replaced by new ones, for example, Level 1, and Level 2.
This is my code so far.
void OnGUI ()
{
int buttonWidth = 350; // The width of the button.
int buttonHeight = 50; // Height of the button
float halfScreenWidth = Screen.width / 2;
float halfButtonWidth = buttonWidth / 2;
GUI.skin = customSkin;
if (GUI.Button(new Rect(halfScreenWidth - halfButtonWidth, 425, buttonWidth, buttonHeight), "Play Game"))
{
Application.LoadLevel ("BattleScene");
}
if (GUI.Button(new Rect(halfScreenWidth - halfButtonWidth, 500, buttonWidth, buttonHeight), "Options"))
{
Application.LoadLevel ("OptionsScene");
}
if (GUI.Button(new Rect(halfScreenWidth - halfButtonWidth, 575, buttonWidth, buttonHeight), "Quit Game"))
{
Application.Quit();
}
}
On push of "Play" you are going to a new BattleScene. Are you creating new scripts there or trying to carry this forward with the scene change?
I am creating new scripts there, this is the only script on the title scene at the moment, I am just trying to get the basics of it and then improve it.
Answer by getyour411 · Jan 30, 2014 at 08:02 AM
I'll assume you are trying to keep all of this in one OnGUI script; so you might have a section here that says
if(Application.loadedLevelName("Battlescene") {
display level 1 button details rect(x,y,w,h);
dsiplay level 2 button " "
etc
}
You might review DontDestroyOnLoad script ref
I think I misunderstood your question about carrying the scripts on. The scene BattleScene, is one of the levels. So what I'm trying to do, is have it when you click the play game button, the scene doesn't change, but the other two buttons appear. Like when you click the options button on a game.
In your code above, "Play" loads a new scene (which is synonymous with Level). If you don't want that, you need to rework to do something like
if(play.button)
displayLevelSelect = true;
if(displayLevelSelect) {
show button for level 1;
show button for level 2;
...
}
That worked great! Thanks heaps. One last thing though, how would I go about making it so that the other buttons disappear when I click "Play"?
Thanks a tonne for the help, really appreciate it, I'm still new to coding.
Your answer
Follow this Question
Related Questions
Button Turns Off and On Object 1 Answer
Button then instanitates gameobject 1 Answer
How to hook up the particle system to jump animation? 1 Answer
Make more buttons appear, on button click. 1 Answer
GUI Button Animation Cue 1 Answer