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 urwrldn3d · Jun 07, 2012 at 07:29 PM · guitoggleactiveskin

GUI Button selected changes color and stays until another button is clicked

Like the long title says. I have a whole bunch of GUI buttons that the user can select particular items from. I have a GUI skin on these and I'm able to make 'normal' and 'hover' work correctly. Active also works, but only when the mouse is down. I'd like for what appears during 'active' to stay that way until another button is pressed.

I've read people suggesting to use GUI toggle. I tried this with no luck though.

 using UnityEngine;
 using System.Collections;
 
     public class GUIsound : MonoBehaviour 
         {
             public GameObject aav71a1;
             public GameObject bv206;
             public GameObject RG33;
             public AudioClip track1;
             public AudioClip track2;
             public AudioClip track3;
             public AudioClip track4;
             private int buttonSelected;
              public float hSbarValue;
              public Vector2 scrollPosition = Vector2.zero;
             public int buttonOffset;
             private int buttonAreaWidth;
             public GUIStyle customstyle;
             public GUIStyle customstyle2;
             public GUIStyle customstyle3;
             public GUIStyle customstyle4;
             public GUISkin skin1;
             public GUISkin skin2;
             public GUISkin skin3;
             
     
     
     void Start()
         {
             aav71a1 = GameObject.Find ("aav71a1");
             bv206 = GameObject.Find ("bv206");
             RG33 = GameObject.Find ("RG33");
             
         
         
             aav71a1.SetActiveRecursively(false);
             bv206.SetActiveRecursively(false);
             RG33.SetActiveRecursively(false);
             buttonSelected = 0;
             buttonOffset = 220;
             buttonAreaWidth = 5985;
             
             
         }
     
     
     void OnGUI()
         {
         GUI.skin = skin1;
         
         
             //Exit Button takes you back to main menu
         if(GUI.Button (new Rect (Screen.width -190, 20,150,70), "EXIT"))
         {
             Application.LoadLevel("Main Menu");
         }    
         switch(buttonSelected)
         {
             case 0:
                 GUI.Label(new Rect(Screen.width / 2 -150, Screen.height / 2 -100, 300, 20), "Select a Vehicle to Study");
                 break;
         case 1:
             GUI.Label(new Rect(Screen.width / 2 -200, Screen.height / 2 - 300, 400, 20), "aav71a1");
             GUI.skin = skin2;
             GUI.Label(new Rect(30, 200, 300, 20), "Country: United States");
             GUI.Label(new Rect(30, 230, 300, 20), "Height: 3 Feet");
             GUI.Label(new Rect(30, 260, 300, 20), "Weight: 95 LBS");
             GUI.skin = skin1;
             break;
         case 2:
             GUI.Label(new Rect(Screen.width / 2 -200, Screen.height / 2 - 300, 400, 20), "bv206");
             break;
         case 3:
             GUI.Label(new Rect(Screen.width / 2 -200, Screen.height / 2 - 300, 400, 20), "RG33");
             break;
         default:
             GUI.Label(new Rect(400, 200, 300, 20), "Select a Vehicle to Study");
                 break;
                 
         }
         //keeps camera from moving while horizontally scrolling through vehicle menu.
         Rect r = new Rect(- 400, Screen.height - 220, buttonAreaWidth, 350);
         
         if (r.Contains(Event.current.mousePosition))
         {
             GetComponent<CameraMove>().enabled = false;
         }
         else
         {
             GetComponent<CameraMove>().enabled = true;
         }
         //creates horizontal scroll bar at the bottom of screen for vehicle button navigation.
         scrollPosition = GUI.BeginScrollView(new Rect(10, Screen.height - 251, Screen.width -20, 250), scrollPosition, new Rect(10, Screen.height - 251, buttonAreaWidth, 0));
     
         if(GUI.Button (new Rect (10,Screen.height - buttonOffset,180,145), "aav71a1"))
         {
             
             
             audio.clip = track1;
             audio.loop = false;
             audio.Play();
             
             aav71a1.SetActiveRecursively(true);
             bv206.SetActiveRecursively(false);
             RG33.SetActiveRecursively(false);
             buttonSelected = 1;
             
             
             
             
         }
         else if(GUI.Button (new Rect (210,Screen.height - buttonOffset,180,145), "bv206"))
         {
             audio.Stop();
             audio.clip = track2;
             audio.loop = false;
             audio.Play();
             
             aav71a1.SetActiveRecursively(false);
             bv206.SetActiveRecursively(true);
             RG33.SetActiveRecursively(false);
             buttonSelected = 2;
             
         }
         else if(GUI.Button (new Rect (410,Screen.height - buttonOffset,180,145), "RG33"))
         {
             audio.Stop();
             audio.clip = track3;
             audio.loop = false;
             audio.Play();
                 
         aav71a1.SetActiveRecursively(false);
             bv206.SetActiveRecursively(false);
             RG33.SetActiveRecursively(true);
             buttonSelected = 3;
                 
         }
         else if(GUI.Button (new Rect (610,Screen.height - buttonOffset,180,145), "UAV4"))
         {
             
         }
         else if(GUI.Button (new Rect (810,Screen.height - buttonOffset,180,145), "UAV5"))
         {
             
         }
         else if(GUI.Button (new Rect (Screen.width - 190,Screen.height - buttonOffset,180,145), "UAV6"))
         {
             
         }
         else if(GUI.Button (new Rect (1210,Screen.height - buttonOffset,180,145), "UAV7"))
         {
             
         }
         else if(GUI.Button (new Rect (1410,Screen.height - buttonOffset,180,145), "UAV8"))
         {
             
         }
         else if(GUI.Button (new Rect (1610,Screen.height - buttonOffset,180,145), "UAV9"))
         {
         
         }
         else if(GUI.Button (new Rect (1810,Screen.height - buttonOffset,180,145), "UAV10"))
         {
         
         }
         else if(GUI.Button (new Rect (2010,Screen.height - buttonOffset,180,145), "UAV11"))
         {
         
         }
         else if(GUI.Button (new Rect (2210,Screen.height - buttonOffset,180,145), "UAV12"))
         {
         
         }
         else if(GUI.Button (new Rect (2410,Screen.height - buttonOffset,180,145), "UAV13"))
         {
         
         }
         else if(GUI.Button (new Rect (2610,Screen.height - buttonOffset,180,145), "UAV14"))
         {    
         
         }
         else if(GUI.Button (new Rect (2810,Screen.height - buttonOffset,180,145), "UAV15"))
         {    
         
         }
         else if(GUI.Button (new Rect (3010,Screen.height - buttonOffset,180,145), "UAV16"))
         {    
         
         }
         else if(GUI.Button (new Rect (3210,Screen.height - buttonOffset,180,145), "UAV17"))
         {    
         
         }
         else if(GUI.Button (new Rect (3410,Screen.height - buttonOffset,180,145), "UAV18"))
         {    
         
         }
         else if(GUI.Button (new Rect (3610,Screen.height - buttonOffset,180,145), "UAV19"))
         {
         
         }
         else if(GUI.Button (new Rect (3810,Screen.height - buttonOffset,180,145), "UAV20"))
         {
         
         }
         else if(GUI.Button (new Rect (4010,Screen.height - buttonOffset,180,145), "UAV21"))
         {
         
         }
         else if(GUI.Button (new Rect (4210,Screen.height - buttonOffset,180,145), "UAV22"))
         {
         
         }
         else if(GUI.Button (new Rect (4410,Screen.height - buttonOffset,180,145), "UAV23"))
         {
         
         }
         else if(GUI.Button (new Rect (4610,Screen.height - buttonOffset,180,145), "UAV24"))
         {
         
         }
         else if(GUI.Button (new Rect (4810,Screen.height - buttonOffset,180,145), "UAV25"))
         {
         
         }
         else if(GUI.Button (new Rect (5010,Screen.height - buttonOffset,180,145), "UAV26"))
         {
         
         }
         else if(GUI.Button (new Rect (5210,Screen.height - buttonOffset,180,145), "UAV27"))
         {
         
         }
         else if(GUI.Button (new Rect (5410,Screen.height - buttonOffset,180,145), "UAV28"))
         {    
             
         }
         else if(GUI.Button (new Rect (5610,Screen.height - buttonOffset,180,145), "UAV29"))
         {
             
         }
         else if(GUI.Button (new Rect (5810,Screen.height - buttonOffset,180,145), "UAV30"))
         {    
             
             
             
         
         }
         GUI.EndScrollView();
         
         
             
         }
     
         }
         
         
Comment
Add comment · Show 1
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 MasterGalaxy · Jun 07, 2012 at 07:38 PM 0
Share

You may have to script the button to change textures while active. I would use a variable to tell which button is down. Another choice may be using a toolbar or selection grid.

http://unity3d.com/support/documentation/ScriptReference/GUI.Toolbar.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Jun 07, 2012 at 07:59 PM

http://unity3d.com/support/documentation/ScriptReference/GUI.SelectionGrid.html

If you want to detect when one is clicked

 int i = GUI.SelectGrid( R, selection, ... );
 if( i != selection ) // Boum
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Toggle and Skin 1 Answer

GUI Toggle Using Button Style Remain Active 1 Answer

Trouble getting GUI phone to open/close 1 Answer

Whats wrong with my GUI.Toggle? 2 Answers

Is there a multiple selection ugui toggle group? 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