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 Eowyn27 · Feb 12, 2014 at 07:53 PM · guitoggle

Why does one GUI change affect every GUI on scene? How can I fix that?

I have this chunk of code:

 if(mainCam.transform.position == new Vector3(1866, 1, -72.4901f)) { 
         
         
             GUI.contentColor = Color.red; 
             GUI.Label (new Rect(20,20,170,30),  "Selecting a stripe is required");
         
             //stripe 1 toggle
             toggleTxt = GUI.Toggle(new Rect(300, 85, 100, 30), toggleTxt, "");
         
             toggleTxt = GUI.Toggle(new Rect(300, 140, 100, 30), toggleTxt, "");
         
             toggleTxt = GUI.Toggle(new Rect(300, 185, 100, 30), toggleTxt, "");
         
             toggleTxt = GUI.Toggle(new Rect(300, 230, 100, 30), toggleTxt, "");
         
             toggleTxt = GUI.Toggle(new Rect(300, 275, 100, 30), toggleTxt, "");
         
             toggleTxt = GUI.Toggle(new Rect(300, 335, 100, 30), toggleTxt, "");
         
             //stripe 7
             toggleTxt = GUI.Toggle(new Rect(300, 380, 100, 30), toggleTxt, "");
         
                 
             
             if(GUI.Button (new Rect (5,Screen.height-40,170,30), "Back")) {
                 print ("You clicked the button!");
                 mainCam.transform.position= new Vector3(0, 1, -10);
                 Camera.main.orthographicSize = 500f;    
         }
     }

I only one the text portion that says "Selecting a stripe is required" in red but I'm not sure how to individualize it for one label? When I change the color of the label, it changes the color of the text for all text on the screen. So now all my labels are red when I only want one label to be red.

Also, I noticed the same thing happen for GUI.toggle feature. I created 7 toggles so that they can be next to a game object for "selecting". However, I want all the toggles to be tied together, so that only one toggle can be selected at a time. Right now, if I select one toggle, all the other toggles are selected as true. If I don't select a toggle, all the other toggles are unselected. I only want to be change to move down the toggles and have them turn on and off (but only one selection in this grid of toggles).

It seems like this problem happens with all the GUI elements. How do I isolate the commands?

Thanks in advance!

This is all written in C#. If a solution is in JS, I can try and translate it into C# :)

EDIT: I figured out how to do the toggle from this post: http://answers.unity3d.com/questions/129813/using-guitoggle-to-onoff-buttons.html

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
1
Best Answer

Answer by robertbu · Feb 12, 2014 at 08:07 PM

How about saving and restoring the color:

 Color savedColor = GUI.contentColor;
 GUI.contentColor = Color.red; 
 GUI.Label (new Rect(20,20,170,30),  "Selecting a stripe is required");
 GUI.contentColor = savedColor;
Comment
Add comment · Show 3 · 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 Eowyn27 · Feb 12, 2014 at 09:12 PM 0
Share

Cool. I assume the same thing can be done for toggle? What is done differently if I save and restore the color? How does that different from what I did previously? Just trying to understand the meaning and logic behind it. Thank you so much robertbu! :D

avatar image robertbu · Feb 12, 2014 at 10:38 PM 0
Share

As you progress from one GUI statement to the next, each statement uses the GUI.contentColor. By saving and restoring the color, we make the GUI.contentColor for the first GUI.Toggle() is the same as it would have been if the color had not been changed at all.

avatar image Eowyn27 · Feb 13, 2014 at 03:03 PM 0
Share

Ah I see. thank you.

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

How does GUI.Toggle work? 2 Answers

Pause Button Problems 2 Answers

Close my GUI button by repressing the same Hot-key. 3 Answers

Gui toggle active inactive states 3 Answers

Only one Checkbox (Bit toggle) at the time 2 Answers


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