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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by jmparavicini · Oct 09, 2014 at 12:12 AM · guibuttonfunctionboolean

Boolean function doesn't work anymore

Hello everyone

Maybe the Title of this question doesn't match 100% but i didnt find a better way to explain it because my problem is that i have this script

     #pragma strict
     
     var BG : Texture2D;
     var skin3 : GUISkin;
     var skin5 : GUISkin;
     var Hover : GUIStyleState;
     var shadow : Texture2D;
     static var inGame = false;
     
     var transformation = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
     
     private var menu = true;
     private var options = false;
     private var credits = false;
     private var Coinshop = false;
     
     var BG2 : Texture2D;
     
     static var myVolume : float;
     
     function Start()
     {
         myVolume = PlayerPrefs.GetFloat("Volume");
     }
     
     function OnGUI () 
     {
     
         GUI.skin = skin3;
         
         if(menu == true)
         {
             GUI.DrawTexture(Rect(Screen.width - Screen.width, Screen.height - Screen.height, Screen.width, Screen.height), BG);
             
             GUI.DrawTexture(Rect(Screen.width / 2 - 600, Screen.height - Screen.height, 1200, 600), shadow);
             
             if(GUI.Button(Rect(Screen.width / 2.65, Screen.height / 2 + Screen.height / 8, 200, 70), "Play"))
             {
                 Application.LoadLevel(1);
             }
             
             if(GUI.Button(Rect(Screen.width - 300, 100, 150, 70), "Exit"))
             {
                 Application.Quit();
             }
             
             if(GUI.Button(Rect(Screen.width / 3.3, Screen.height / 4 + Screen.height / 3.7, 270, 70), "Settings"))
             {
                 menu = false;
                 options = true;
                 credits = false;
                 Coinshop = false;
             }
             
             if(GUI.Button(Rect(Screen.width / 3.3, Screen.height /2 + Screen.height / 4, 270, 70), "Credits"))
             {
                 menu = false;
                 options = false;
                 credits = true;
                 Coinshop = false;
             }
             
             if(GUI.Button(Rect(Screen.width / 1.2,  Screen.height / 4 + Screen.height / 3.7, 370, 70), "Coin Shop"))
             {
                 menu = false;
                 options = false;
                 credits = false;
                 Coinshop = true;
             }
         }
         if(options == true)
         {
             if(Input.GetKeyDown(KeyCode.Escape))
             {
                 var menu = true;
                 var options = false;
                 var credits = false;
                 var Coinshop = false;
             }
             GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), BG2);
             GUI.Label(Rect(Screen.width / 2 - 155, Screen.height / 15, 310, 70), "Settings");
             
             GUI.skin = skin5;
             GUI.Label(Rect(Screen.width / 2 - 85, Screen.height / 5 - 50 , 170, 70), "Volume");
             myVolume = GUI.HorizontalSlider (Rect (Screen.width / 2 - 300, Screen.height / 5, 600, 70), myVolume, 0.0, 1.0);
         }
         
         if(Coinshop == true)
         {
             GUI.skin = skin3;
             GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), BG2);
             
             GUI.Label(Rect(Screen.width / 2 - 250, Screen.height / 15, 500, 70), "Coin Shop");
         
             
             GUI.skin = skin5;
             GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3.5 + 5, 250, 70), "Coins: " + CoinMaster.Coins);
             
             
             GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3, 500, 70), "Flashlight Range: " + PlayerPrefs.GetFloat("Range"));
             if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3, 500, 70), "Flashlight Range") && CoinMaster.Coins >= 1 && lightTransporter.myRange <= 50)
             {
                 lightTransporter.myRange += 1;
                 CoinMaster.Coins -= 1;
             }
             
             
             GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3 + 100, 500, 70), "Flashlight Intensity: " + PlayerPrefs.GetFloat("Intensity"));
             if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3 + 100, 500, 70), "Flashlight Intensity") && CoinMaster.Coins >= 1 && lightTransporter.myIntensity <= 2)
             {
                 lightTransporter.myIntensity += 0.1;
                 CoinMaster.Coins -= 1;
             }
        
             
             GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3 + 200, 500, 70), "Flashlight Angle: " + PlayerPrefs.GetFloat("Angle"));
             if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3 +200, 500, 70), "Flashlight Angle") && CoinMaster.Coins >= 1 && lightTransporter.myAngle <= 50)
             {
                 lightTransporter.myIntensity += 0.1;
                 CoinMaster.Coins -= 1;
             }
             
             
             GUI.Label(Rect(Screen.width / 2 +300, Screen.height / 3 + 300, 500, 70), "Flashlight Life: " + PlayerPrefs.GetFloat("Drainspeed"));
             if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3 + 300, 500, 70), "Flashlight life")  && CoinMaster.Coins >= 1 && Flashlight.drainSpeed >= 0.1)
             {
                 CoinMaster.Coins -= 1;
                 Flashlight.drainSpeed -= 0.1;
             }
             
             if(GUI.Button(Rect(Screen.width / 2 -50, Screen.height / 2 + Screen.height / 2.8, 100, 70), "Back"))
             {
                 menu = true;
                 options = false;
                 credits = false;
                 Coinshop = false;
             }
             if(Input.GetKeyDown(KeyCode.Escape))
             {
                 menu = true;
                 options = false;
                 credits = false;
                 Coinshop = false;
             }
             
         }
         
         if(credits == true)
         {
             if(Input.GetKeyDown(KeyCode.Escape))
             {
                 credits = false;
                 options = false;
                 menu = true;
                 Coinshop = false;
             }
         }
     }
     
     function Update()
     {
         
         PlayerPrefs.SetFloat("Volume", myVolume);
   }

And All Button work except the CoinShop doesnt work in the inspector you can see that it actually marks as true when i press the button but it doesnt call up the CoinShop. Thanks in advance and sorry for the confusion skullbeats1

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 Landern · Oct 09, 2014 at 04:21 AM 0
Share

Is lightTransporter, Coin$$anonymous$$aster and Flashlight static classes, there are ZERO references other than usage of these variables.

2 Replies

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

Answer by crodriguez · Oct 11, 2014 at 01:47 AM

By any chance do you also have Coinshop as a class? Because if so, it might be confusing it with that. So instead of writing:

 private var Coinshop = false;

Change the name to:

 private var coinShop = false;
Comment
Add comment · Show 1 · 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 jmparavicini · Oct 11, 2014 at 01:00 PM 0
Share

i tried that too but it didnt work

avatar image
1

Answer by Redeemer86 · Oct 09, 2014 at 06:52 AM

Ok, try this ... Wherever you are reassigning Boolean values in your code. Set all the false booleans first and at the end set the true Boolean. Like if menu = false, options = true! credits = false, coinshop = false... Change the ordering of the statements so put the statements assigning false value first and the statement assigning true statement last. Do this throughout where you have blocks setting thee four booleans accordingly. Remember to order with the true valued assignment only after setting the false ones in that block/ condition... See if it works, Red.

Comment
Add comment · Show 4 · 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 jmparavicini · Oct 09, 2014 at 09:36 PM 0
Share

No it doesnt seem to work :(

avatar image Redeemer86 · Oct 11, 2014 at 08:07 AM 0
Share

I tried your code with my modification... Works for me ... Strange ...

avatar image jmparavicini · Oct 11, 2014 at 01:00 PM 0
Share

veeeery strange

avatar image jmparavicini · Oct 11, 2014 at 03:14 PM 1
Share

ok i found the problem i had in the options menu var's i dont know why but they made a conflict that was the reason why it didnt work

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

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

Related Questions

UI button doesn't appear - c# 3 Answers

Button is unable to grab functions with two parameters? 0 Answers

How do I make the buttons work on this GUI? 2 Answers

Does anyone know about BeingChangeCheck function? 0 Answers

determine the minimum time for the player to hold the 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