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 Clopay · Jan 03, 2013 at 08:46 PM · buttonsgui-buttonmainmenugui-skin

Main Menu GUI Button - Animation?

Hey fellow Uniters,

So I've got a predicament here that many others seem to have; however, I've tested every solution from each search result to no avail! I've racked my brain/the internet for days as to a possible solution, but have none - hence my question here.

I've got a basic working Main Menu. I created a string array for the menu options, assign names to the options in the inspector, and then create a for (each item in the string array) - loop to create buttons. Looks alright. I've even got a custom GUIskin assigned that changes text color/texture of the focused option, so I can tell which menu option I'm currently on. (I opted for the "For loop" for my buttons as opposed to a "Selection Grid," as the latter of the two is far less customizable). This is all navigable by keyboard - I can key up/down and pick an option and I'd like to keep it that way. I have the GUI.SetNextControlName within the for loop, and a GUI.FocusControl after my selection code, although I'm not really sure they do anything or how they work. But here's where my real problem lies - animation.

Question 1 How can I access the focused menu option through scripting in order to animate it (I'd be using iTween, because...well, if you haven't used it yet, use it!)? I've seen a few people put their button specifications within an "If" statement; however, that appears to only be useful for single button creation. I haven't seen it done in a "for - loop" button creation system. I'd simply like to access the menu item that has keyboard focus and scale it to be just a tad bigger, but GUIskin only offers parameters for texture and text.

Question 2 Once I've established a working animation for each icon, how can I completely eliminate the mouse functions? I would like the mouse to NOT affect the menu whatsoever. That means the GUIskin does not react to mouse hovers or clicks. Since the GUIskin does not appear to have a disable function for those, should I eliminate the GUIskin altogether and assign textures via scripting? If I do that, how could I access the highlighted option (focused, but not yet pressed/activated) in order to change texture, text color, and animate?

Question 3 Submenus. I'm not sure where to start with this, so I'll more than likely make another post. But while we're on the topic - what's the best way of creating a submenu? The only way I've seen it done is enumeration. I have not yet tried anything yet, but I really don't want to dive into it and become even more irritated with Unity's current GUI system. But it's nice to know in advance for planning purposes :)

Thank you in advance!

-Clopay

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Davidovich · Jan 04, 2013 at 09:52 PM

Question 1

You can use GUIUtility.keyboardControl to get the ID of the focussed element, then compare that against the control ID.

Example code in C# (Unityscript version is almost identical)

 GUIContent content = new GUIContent("I'm a button!");
 int controlId = GUIUtility.GetControlID(content, FocusType.Keyboard);
 if (GUIUtility.keyboardControl == controlId) {
     Debug.Log("It's got focus - " + controlId);
 }
 
 if (GUI.Button(new Rect(10,10,100,30), content)) {
     Debug.Log("Clicked the control button");
 }

Question 2 For this you can check GUIUtility.hotControl. This will be 0 if nothing has been clicked, or the ID of the element that was clicked

Example in C#

 bool guiClick = (GUIUtility.hotControl != 0);
 
 if (GUI.Button(new Rect(10,10,100,30), content) && !guiClick) {
     Debug.Log("Pressed the control button");
 }

Question 3

The best way I've seen of doing submenus is by using delegates. This is much cleaner than great big switch statements and the like. The first thing that turned up was this: http://forum.unity3d.com/threads/22252-Friday-Treat-GUI-Menu-System-(C-)

There are also a bunch of other resources that I can't find at the moment :(

The implementation of delegates is a bit different between C# and Unityscript, but there was a post on implementing a Unityscript version here: http://answers.unity3d.com/questions/50164/how-can-i-use-function-pointerdelegate-in-pragma-s.html

Hope that helps some!

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

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

9 People are following this question.

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

Related Questions

On Screen Button Controls 0 Answers

Main menu help needed (C#) 2 Answers

Why do my GUI.button Background Colors Not work? 1 Answer

2 Position GUI Texture Rocker Switch 0 Answers

GUI Buttons not Being Displayed 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