Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Foggy321 · Jan 30, 2014 at 07:57 AM · guibuttontitle

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();
         }
     }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Jan 30, 2014 at 07:59 AM 0
Share

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?

avatar image Foggy321 · Jan 30, 2014 at 08:02 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Foggy321 · Jan 30, 2014 at 08:12 AM 0
Share

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.

avatar image getyour411 · Jan 30, 2014 at 08:19 AM 0
Share

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;
 ...
 }
avatar image Foggy321 · Jan 30, 2014 at 08:26 AM 0
Share

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"?

avatar image getyour411 · Jan 30, 2014 at 08:30 AM 0
Share
 if(!displayLevelSelect) {
 
 // do that stuff
 
 }
avatar image Foggy321 · Jan 30, 2014 at 08:35 AM 0
Share

Thanks a tonne for the help, really appreciate it, I'm still new to coding.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges