Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 question was closed May 25, 2013 at 08:57 PM by Fattie for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by primus88 · May 25, 2013 at 03:40 PM · scripting problemguiif-statements

Why my 'if' condition is not working

Hello,

I have this script which should only work when the menuactive = true, but in fact it's completly ignoring, so the GUI menu continues to show :

 void OnGUI(){
             
     if(menuactive){
             
         if(GUI.Button(new Rect(410, 750, 100, 26), "Tab to Hide")){
             }
          // when my set time is reached
         if (myCounter1 >= mySetTime1) {
         // show GUI Button
             //BUY GOBLIN
         if (GUI.Button(new Rect(410, 800, 210, 26), "1. Buy Goblin: 50 Gold")) {            
         myCounter1 = 0;
         }
         }
             else{
                 GUI.Button(new Rect(410, 800, 210, 26), "Cooldown");
             }
             
         if (myCounter2 >= mySetTime2) {
         // show GUI Button
             //BUY ARCHER
         if (GUI.Button(new Rect(630, 800, 210, 26), "2. Buy Archer: 60 Gold")) {
         myCounter2 = 0;
         }
         }
             else{
                 GUI.Button(new Rect(630, 800, 210, 26), "Cooldown");
             }
         // add time to counter
         // use myCounter++; (same as myCounter+=1;) to count the frames - or
         myCounter1 += Time.deltaTime; 
         myCounter2 += Time.deltaTime;
  }
         
 }

And second, How can I make my Cooldown button system to work when I press a key and not by mouse click (as is is now).

Thank you

Comment
Add comment · Show 4
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 robertbu · May 25, 2013 at 03:49 PM 0
Share

The likely issue is whatever code you are using to set 'menuactive', not this code. Put this code on line 2:

 if (!menuactive)
   Debug.Log("$$anonymous$$enu Inactive");

Note you might also look to make sure you don't have this script attached to multiple objects.

avatar image primus88 · May 25, 2013 at 04:10 PM 0
Share

Solved it. For some reason works only by using static variables. $$anonymous$$eh.. :D

Thank for the help. Now I only need to understand how can I activate that cooldown by being triggered by keys and not by mouse button.

Any ideas ?

avatar image primus88 · May 25, 2013 at 04:50 PM 0
Share

I put it like this :

if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.C)){ myCounter1 += Time.deltaTime; }

Bad move, as it freezes my counter completly... Where to put it exactly ?

avatar image primus88 · May 25, 2013 at 08:24 PM 0
Share

Solved it. I just put myCounter1 and 2 as condition in my spawn script.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · May 25, 2013 at 04:43 PM

 // Check for the 'C' key press
 if (Input.GetButtonDown(KeyCode.C)) {
 
     // Start the cooldown.
 }
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

Follow this Question

Answers Answers and Comments

13 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

Related Questions

Why is OnGUI not working? 1 Answer

GUI.skin Does not persist on next loop through is this a bug? 0 Answers

Vertical distance indication 1 Answer

3 Days and I still can't figure out c# reflection, please help? Trying to use a protected Type and method. 1 Answer

Unity GUI Style with if Statements 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