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 paco morales · Jan 30, 2013 at 06:24 AM · guienabledvar

Two variables in a GUI Button?

Hello everyone,

I'm working in a GUI with three buttons, if I hit one button the other two or one came disabled, depending of the requirement.

Now I'm trying to use two Var "GUI.enabled = emble;" and " GUI.enabled = bate:" in a single GUI button.

If I use one var it works, but I can't use both...

I did try this, but without any success..

 GUI.enabled = bate,emble;

If I use this, only the first works...

     GUI.enabled = bate;
     GUI.enabled = emble;
        GUI.skin = Skin_battery;
     if (GUI.Button(Rect(870,470,80,39),"")){
     battery();
       
     } 

How I can use both, if I need two or one?

Please any help is more than welcome!

And this is my script GUI Buttons Script.

 evar Skin_tool : GUISkin;
 var Skin_battery : GUISkin;
 var Skin_Disassemble : GUISkin;
 var beep : AudioClip;
 
 var bate = true; 
 var emble = true;
  
 function OnGUI (){
 
     ////////////////////////////////////////
     //BATTERY
  
     GUI.enabled = emble;
        GUI.skin = Skin_battery;
     if (GUI.Button(Rect(870,470,80,39),"")){
     battery();
       
     } 
  
     //DISASSEMBLE
  
     GUI.enabled = bate; 
     GUI.skin = Skin_Disassemble;
     if (GUI.Button(Rect(870,512,80,80),"")){
     disassemble();
      
      }
      
      //TOOL
      
     GUI.enabled = bate; 
        GUI.skin = Skin_tool;
     if (GUI.Button(Rect(870,345,80,80),"")){
      }
        } 
        
        function battery() {
 
     if(bate) {
      
        bate = !bate;
     }
     else {  
        bate = !bate;
     }
     }    
  
     function disassemble() {
 
     if(emble) {
       emble = !emble;
     }
     else {
       emble = !emble;
     }
     }nter code here
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

Answer by CodeMasterMike · Jan 30, 2013 at 06:45 AM

If I understand you correctly, you want that the buttons are enabled/diabled depending on these two booleans being true/false?

GUI.enabled = bate,emble;

Doesn't work, since you have two different booleans tellig the GUI to be enabled or not.

GUI.enabled = bate;

GUI.enabled = emble;

Does work because the emble boolean overwrites whatever the bate boolean set before it.

Maybe you would want to something like this, instead:

 private bool GetABooleanValue()
 {
     if(bate == false && emble == false)
     {
         return false;
     }
     else if(bate == false && emble == true)
     {
         return false;
     }
     else if(bate == true && emble == false)
     {
         return false;
     }
     else
     {
         return true;
     }
 }
 
 function OnGUI ()
 {
     ////////////////////////////////////////
     //BATTERY
  
     GUI.enabled = GetABooleanValue();
     GUI.skin = Skin_battery;
     if (GUI.Button(Rect(870,470,80,39),""))
     {
         battery();
     }
     
     // Rest of the code here...
 
 }

Now you have four different options to disable/enable your buttons depending on what these two booleans are set to.

Good luck!

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 paco morales · Jan 30, 2013 at 09:37 AM 0
Share

Thanks Code$$anonymous$$aster$$anonymous$$ike for your time and help. I did try your code but is not working. $$anonymous$$aybe I'm missing something?

Please take a look to the script.

Thanks Again!

     var Skin_tool : GUISkin;
     var Skin_battery : GUISkin;
     var Skin_Disassemble : GUISkin;
     var beep : AudioClip;
 
     var bate = true; 
     var emble = true;
 
 
     private bool GetABooleanValue(){
 
     if(bate == false && emble == false){
 
     return false;
 
     }else if(bate == false && emble == true){
 
     return false;
 
     }else if(bate == true && emble == false){
 
     return false;
 
     }else{
 
     return true;
     }
     }
 
 
     function OnGUI (){
  
     //BATTERY
  
     GUI.enabled = GetABooleanValue();
     GUI.skin = Skin_battery;
     if (GUI.Button(Rect(870,470,80,39),"")){
     battery();
     }
 
     //DISASSE$$anonymous$$BLE
 
     GUI.enabled = bate; 
     GUI.skin = Skin_Disassemble;
     if (GUI.Button(Rect(870,512,80,80),"")){
     disassemble();
 
     }
 
     //TOOL
 
     GUI.enabled = bate; 
     GUI.skin = Skin_tool;
     if (GUI.Button(Rect(870,345,80,80),"")){
     }
     } 
 
 /////////////////////////////////////////////////
 
     function battery() {
 
     if(bate) {
 
        bate = !bate;
     }
     else {  
        bate = !bate;
     }
     }   
 
     function disassemble() {
 
     if(emble) {
       emble = !emble;
     }
     else {
       emble = !emble;
     }
     }  
  
avatar image CodeMasterMike · Jan 30, 2013 at 11:19 AM 0
Share

You shouldn't copy and paste. It was just a example code. You should change in the GetABooleanValue function so it returns the rigt values that you want.

I jus set the if-statements and the return values to any values, since I don't know what kind of result you want to get.

Use the GetABooleanValue function to check if emble and bate is true, or not.

And if one of them, both or none of them is true, return your boolean value if the button should be active, or not.

So look over the function and change it so it returns the values you want to have.

Below, it should be working. Battery is depending on emble, DISASSE$$anonymous$$BLE is depending on bate, and the TOOL is depending on both of them.

     var Skin_tool : GUISkin;
     var Skin_battery : GUISkin;
     var Skin_Disassemble : GUISkin;
     var beep : AudioClip;
  
     var bate = true; 
     var emble = true;
  
  
     private bool GetABooleanValue(){
  
     if(bate == false && emble == false){
  
     return true;
  
     }else if(bate == false && emble == true){
  
     return false;
  
     }else if(bate == true && emble == false){
  
     return false;
  
     }else{
  
     return true;
     }
     }
  
  
     function OnGUI (){
  
     //BATTERY
  
     GUI.enabled = emble;
     GUI.skin = Skin_battery;
     if (GUI.Button(Rect(870,470,80,39),"")){
     battery();
     }
  
     //DISASSE$$anonymous$$BLE
  
     GUI.enabled = bate; 
     GUI.skin = Skin_Disassemble;
     if (GUI.Button(Rect(870,512,80,80),"")){
     disassemble();
  
     }
  
     //TOOL
  
     GUI.enabled = GetABooleanValue(); 
     GUI.skin = Skin_tool;
     if (GUI.Button(Rect(870,345,80,80),"")){
     }
     } 
  
 /////////////////////////////////////////////////
  
     function battery() {
  
     if(bate == true) {
  
        bate = false;
     }
     else {  
        bate = true;
     }
     }   
  
     function disassemble() {
  
     if(emble == true) {
       emble = false;
     }
     else {
       emble = true;
     }
     }  
avatar image paco morales · Jan 31, 2013 at 05:24 AM 0
Share

Thanks Code$$anonymous$$aster$$anonymous$$ike for your help, Now is working :)

 var Skin_tool : GUISkin;
 var Skin_battery : GUISkin;
 var Skin_Disassemble : GUISkin;
 var beep : AudioClip;
  
 var bate = true;
 var emble = true;
  
  
 private function GetABooleanValue(): boolean{
  
 if(bate == false && emble == false){
  
 return true;

  
 }else{ if(bate == false && emble == true){
  
 return false;
 
  
 }else{ 
 
 if(bate == true && emble == false){
  
 return false;
 
  
 }else{
  
 return true;
 }
 }
 } 
 } 
 function OnGUI (){
  
 //BATTERY
  
 GUI.enabled = emble;
 GUI.skin = Skin_battery;
 if (GUI.Button(Rect(870,470,80,39),"")){
 battery();
 }
  
 //DISASSE$$anonymous$$BLE
  
 GUI.enabled = bate;
 GUI.skin = Skin_Disassemble;
 if (GUI.Button(Rect(870,512,80,80),"")){
 disassemble();
  
 }
  
 //TOOL
  
 GUI.enabled = GetABooleanValue();
 GUI.skin = Skin_tool;
 if (GUI.Button(Rect(870,345,80,80),"")){
 }
 }
  
 /////////////////////////////////////////////////
  
 function battery() {
  
 if(bate == true) {
  
 bate = false;
 }
 else {
 bate = true;
 }
 }
  
 function disassemble() {
  
 if(emble == true) {
 emble = false;
 }
 else {
 emble = true;
 }
 } 

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

10 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

Related Questions

mouse displays GUI text when on objects 3 Answers

A node in a childnode? 1 Answer

Assigning two variables ? 1 Answer

HorizontalScrollbar not appearing in GUILayout.BeginScrollview C# 3 Answers

3D Button? 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