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
-1
Question by ramjigeddam · Nov 25, 2013 at 09:45 AM · javascriptguibutton

I have doubt please help me

I have two buttons button-A and button-B. If button-A in active position then button-B in detective position vice versa. please help me in code in java script unity. I have no ideas coming till now.

Comment
Add comment · Show 8
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 wijesijp · Nov 25, 2013 at 09:50 AM 0
Share

are they done in OnGUI function?

avatar image thef1chesser · Nov 25, 2013 at 10:04 AM 0
Share

could you post what you tried so far?

avatar image Fornoreason1000 · Nov 25, 2013 at 10:13 AM 0
Share

You Haven't really asked a question... I don't know what you mean by "detective" position

I think you mean Active state and Normal state. Button are not too suited for this , use GUI.Toggle with a button style.

  var a = false
 function OnGUI() {
 a = GUI.Toggle(Rect(0,0,80,20), a , "A", GUI.skin.button);
 var b = !a;
 GUI.Toggle(Rect(0,30,80,20), b , "B", GUI.skin.button);
 
 }
avatar image ArkaneX · Nov 25, 2013 at 10:23 AM 0
Share

@ramjigeddam - please watch a video tutorial and learn how to properly format the code you post.

avatar image thef1chesser · Nov 25, 2013 at 10:24 AM 0
Share

For what I understand he wants to activate and deactivate buttons. So you can't press both...

Could you edit the comments so everything is outlined and readable.

Show more comments

2 Replies

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

Answer by zVolodymyr · Nov 25, 2013 at 11:43 AM

Something like that?

 if(GUI.Toggle (new Rect(5, 70, 100, 30), canRotate, "Activate"))
   canRotate=true;
 if(GUI.Toggle (new Rect(5, 70, 100, 30), !canRotate, "Deactivate"))
   canRotate = false;
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
avatar image
0

Answer by Bunny83 · Nov 25, 2013 at 10:46 AM

Not sure if i got your question right. So you want two buttons like a radio-button-group where one 1 active the other not. The easiest way is to use Toggles. Depending on your desired behaviour one of those:

 //version1
 function OnGUI()
 {
     if (GUI.Toggle(new Rect(5, 70, 100, 30), canRotate, "Activate", "Button"))
     {
         canRotate = true;
     }
     if (GUI.Toggle(new Rect(5, 110, 100, 30),!canRotate, "Deactivate", "Button"))
     {
         canRotate = false;
     }
 }

 //version2
 function OnGUI()
 {
     canRotate =  GUI.Toggle(new Rect(5, 70, 100, 30), canRotate, "Activate", "Button");
     canRotate = !GUI.Toggle(new Rect(5, 110, 100, 30),!canRotate, "Deactivate", "Button");
 }

Version 1 works like a true radio button group, so when you click one it gets active and if you click again it stays active.

Version 2 are just alternating toggles, so if you press either of the buttons they toggle the state

You probably want version 1.

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

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

Related Questions

Rigidbody Gravity scripting question (Javascript Answers Only!) 3 Answers

DrawTexture GUI iPhone 1 Answer

How can I attach a GUI.Button to a variable? 2 Answers

GUI.Button gets clicked automatically 1 Answer

How can I make a gui with buttons pop up in javasript? 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