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 Tyrebear · Mar 02, 2014 at 02:29 PM · menubuttonsfollowloops

How can I make a button follow the menu it's attached to?

Hello I am working on a game that has a small form factor menu that slides out when the player presses it. The menu has a set of 3 buttons that when pressed, will collapse themselves and make room for another set of buttons. Think of it like a sub-menu. Anyways I have been able to make the buttons collapse themselves but I cannot get them to follow the slide-out menu when it is pressed.

Because of the Unity Answers limitations I cannot attach more than 2 example pictures so please visit my personal portfolio website located here http://w3.cnm.edu/~tteichelmann/unity/

Here is my script

var MyBoxLeft = -200.0; var MyButtonsLeft = 0.0; var MyButtonsLeftSizeX = 200.0; var SupplyButtonsLeft = 0.0; var SupplyButtonsLeftSizeX = 200.0; var icon: Texture; var icon2: Texture; var icon3: Texture; var menuSkin: GUISkin; var muunaBurger: float = 2.50; var glucks: float = 1.50; var bopster: float = 4.00; //Total Burgers and Position var totalBurgers: int; var burgerPos: Vector2 = new Vector2(0, 0); var burgerSize: Vector2 = new Vector2(0, 0); //Total Glucks and Position var totalGlucks: int; var glucksPos: Vector2 = new Vector2(0, 0); var glucksSize: Vector2 = new Vector2(0, 0); //Total Glucks and Position var totalBopsters: int; var bopsterPos: Vector2 = new Vector2(0, 0); var bopsterSize: Vector2 = new Vector2(0, 0); var globalMoney: float = 100; var TextPosition: Vector2 = new Vector2(44, 0); var TextSize: Vector2 = new Vector2(134, 20.5); function OnGUI() { GUI.skin = menuSkin; var tBoxRect = new Rect(MyBoxLeft, 300.0, 220, 80); var tBoxRect2 = new Rect(MyBoxLeft + 200, 120, 20, 260); var tButtonRect = new Rect(MyBoxLeft, 120.0, 200, 60); var tButtonRect2 = new Rect(MyBoxLeft, 180.0, 200, 60); var tButtonRect3 = new Rect(MyBoxLeft, 240.0, 200, 60); var tBoxArt = new Rect(MyBoxLeft, 240.0, 120, 120); var buttonSet1Rect1 = new Rect(MyBoxLeft, 120.0, 200, 60); var buttonSet1Rect2 = new Rect(MyBoxLeft, 180.0, 200, 60); var buttonSet1Rect3 = new Rect(MyBoxLeft, 240.0, 200, 60); var mousePos: Vector2 = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y); //Background and icons GUI.Box(tBoxRect, icon); GUI.Box(tBoxRect2, icon3); GUI.DrawTexture(Rect(tBoxRect2), icon3, ScaleMode.StretchToFill); if (Input.GetButtonDown("Fire1") && tBoxRect.Contains(mousePos) || Input.GetButtonDown("Fire1") && tBoxRect2.Contains(mousePos)) { AnimateBox(); } // GUI.Box(tBoxArt, icon2); GUILayout.BeginArea(Rect(MyButtonsLeft, 0, MyButtonsLeftSizeX, 520)); //When Button is pressed then slide to the right to make room for more buttons. if (GUI.Button(tButtonRect, "Buy Supplies")) { AnimateMenu(); GUI.Button(buttonSet1Rect1, "Buy Muuna Burgers"); GUI.Button(buttonSet1Rect2, "Buy Glucks"); GUI.Button(buttonSet1Rect3, "Buy Bopsters"); CreateNewButtons(); } GUI.Button(tButtonRect2, "Upgrades"); GUI.Button(tButtonRect3, "Stats & Employees"); GUILayout.EndArea(); // //Amount of supplies if (totalBurgers >= 999) { totalBurgers = 999; } if (totalGlucks >= 999) { totalGlucks = 999; } if (totalBopsters >= 999) { totalBopsters = 999; } GUILayout.BeginArea(Rect(MyBoxLeft, burgerPos.y, burgerSize.x, burgerSize.y)); var burgerAmount: String = "" + totalBurgers; GUILayout.Label("Muuna Burgers : " + burgerAmount); GUILayout.EndArea(); GUILayout.BeginArea(Rect(MyBoxLeft, glucksPos.y, glucksSize.x, glucksSize.y)); var glucksAmount: String = "" + totalGlucks; GUILayout.Label("Glucks : " + glucksAmount); GUILayout.EndArea(); GUILayout.BeginArea(Rect(MyBoxLeft, bopsterPos.y, bopsterSize.x, bopsterSize.y)); var bopsterAmount: String = "" + totalBopsters; GUILayout.Label("Bopsters : " + bopsterAmount); GUILayout.EndArea(); // //Money GUI.Label(Rect(TextPosition.x, TextPosition.y, TextSize.x, TextSize.y), "$" + globalMoney); // } function AnimateBox() { if (MyBoxLeft == -200.0) { while (MyBoxLeft < 0.0) { MyBoxLeft += 5.0; yield; } } else if (MyBoxLeft == 0.0) { while (MyBoxLeft > -200.0) { MyBoxLeft -= 5.0; MyButtonsLeft -= 5.0; MyButtonsLeft = 0.0; yield; } } } function AnimateMenu() { if (MyButtonsLeft == 0.0) { while (MyButtonsLeft < 180){ //fix this line, While at any time MyButtonsLeft < 180 the menu can be retracted, causing an error MyButtonsLeft += 5.0; MyButtonsLeftSizeX -= 5.0; yield; } } else if (MyButtonsLeft == 180) { //Fix this line, need to figure out how to retract MyButtonsLeft when MyBoxLeft is pressed and MyButtonsLeftSizeX = 20 while (MyButtonsLeft > 0.0) { MyButtonsLeft -= 5.0; MyButtonsLeftSizeX += 5.0; yield; } } } function CreateNewButtons() { if (SupplyButtonsLeft == 0.0){ while (SupplyButtonsLeft < 20){ SupplyButtonsLeft+=5.0; yield; } } while (SupplyButtonsLeft > 0.0){ SupplyButtonsLeft-= 5.0; yield; } }

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

20 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 avatar image avatar image

Related Questions

Menu not working correctly. 0 Answers

UI Buttons - affects all 0 Answers

dosent work 0 Answers

[Partially Solved] OnClick of one button, show different set of buttons. 1 Answer

uitoolkit slide out menu? (made for mobile but taking all ideas, except for OnGUI calls) 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