• 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
1
Question by beco13 · Jun 27, 2011 at 08:04 AM · guibutton

controlling GUI.Button state

How do I control a GUI button state?

I want to have a button that remains active until I press another button.

Comment
Add comment · Show 7
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 beco13 · Jun 27, 2011 at 08:43 AM 0
Share

I don't think it's the answer....

C$$anonymous$$IIW , your code, is apparently using two different buttons right? creating another button and overwrite the previous... what I want is that to control the button like , the hover state or the active state or normal state.... Sorry if I get this wrong... :)

avatar image Kacer · Jun 27, 2011 at 08:49 AM 0
Share

you're quite right, it is using two buttons. Have you tried using a GUIlayout.Toggle ?

its not a button in itself, but its got an on/off state. i'll make some links in the answer i made

avatar image beco13 · Jun 27, 2011 at 09:17 AM 0
Share

Yes I did use the toggle button....But its da*n ugly...hahahaha... :)

The link is close to the answer, but it hasn't been solved either... :(

avatar image Kacer · Jun 27, 2011 at 09:58 AM 0
Share

well, you can always use your own skin for the GUI:

http://unity3d.com/support/documentation/Components/class-GUISkin.html

avatar image beco13 · Jun 27, 2011 at 10:00 AM 0
Share

well...I think that solved the problem... for the layout...:)

I've just got an enlightment...hahahaha still working on the scripts though. :) tq for your solution...

Show more comments

1 Reply

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

Answer by Kacer · Jun 27, 2011 at 08:26 AM

You can use something like this:

    public class guiTest : MonoBehaviour {

    public bool pressedbool = false;
     
     
     void OnGUI(){
         if(!pressedbool){
             if(GUILayout.Button("press me to show your secrets", GUILayout.Width(400))){
                 pressedbool = true; 
             }
         }else{
             if(GUILayout.Button("OMG I DONT WANT TO SEE THAT", GUILayout.Width(400))){
                 pressedbool = false;
             }
         }
         
         
         if(pressedbool){
             pressed();
         }
     }
     
     public void pressed(){
         GUILayout.BeginHorizontal();
         GUILayout.Label("you have pressed the first button, press the second button and this will dissapear");
         GUILayout.EndHorizontal();
     }
 
 }

-Kacer

EDIT;

you can use the toggle:

http://unity3d.com/support/documentation/ScriptReference/GUILayout.Toggle.html

though, if you want unity to see if you're hovering over a gui element it becomes something else, im not quite sure on how to do it, but this link might help, there's some posts with code down the page, which seems to work, in theory at least :)

http://forum.unity3d.com/threads/6777-GUI.Button()-hover-detection

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Making a Hover function for a button or toolbar from code. 2 Answers

Question about positioning GUI. 1 Answer

Button reaction time problem 1 Answer

How to change a GUI button texture through scripting 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