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 husbandofemily · Mar 19, 2013 at 07:36 PM · if statement

two if() statements with one GetKeyDown won't work.

Hi all, I've looked but can't find the answer anywhere else, sorry if it's out there and I can't find it. All I want to do is call one of two separate coroutines with one key press, depending on the state of another boolean variable. The following works fine.....

 if(Input.GetKeyDown(KeyCode.I) && follow)
                 {
                     bcOn();
                         
                 }
         if(Input.GetKeyDown(KeyCode.O) && boardChopper)
                 {
                     followOn();                    
                 }

however, if I change that O keystroke to an I, it doesn't work. No errors in the console, but the coroutines aren't called. It's driving me mad! I know it's coding 101 (ha, binary joke), and I'm missing something really simple, but I just can't see it.

Any help greatly appreciated

Ian

Comment
Add comment · Show 2
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 hoy_smallfry · Mar 19, 2013 at 07:49 PM 0
Share

I notice you're using &&. Sanity check time! Check if follow and boardChopper are true. If one of them isn't, then that might explain why you aren't getting two calls.

avatar image husbandofemily · Mar 19, 2013 at 10:19 PM 0
Share

Thanks, but I have. Like I say, the code itself works fine with another key subbed in for one set of code, and the letter "I"'s not used elsewhere. Very strange :-/

1 Reply

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

Answer by xt-xylophone · Mar 19, 2013 at 07:48 PM

So you want to call either bcOn or boardChopper if you push the 'I' key based on the 2 booleans? Try something like this...

 if(Input.GetKeyDown(KeyCode.I))
 {
     if(follow)
     {
         bcOn();
     }
 
     if(boardChopper)
     {
         followOn();
     }
 }

Not tested but if I understand you correctly, should work :D

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 husbandofemily · Mar 19, 2013 at 08:47 PM 0
Share

Good call, I can see it will work. I just wish I knew why my code won't work, when it does with a different key assigned. Weird. Either way, thanks :-)

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

12 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

Related Questions

if Statement Help Increment Value 2 Answers

Why can't I use == in mono develop? 1 Answer

if statement or just setting transform.position? 1 Answer

How to determine if your List has more than 1 of the same object listed? 1 Answer

Check if gravity is inverted 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