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 CrilleStyles · Jun 08, 2014 at 09:19 AM · noobkey

Hold down 2 buttons and do something

I wonder how to make if I hold down W and Shift it will do something. I think I should do It like this but I'm not sure

 if(Input.GetKey("W" && "LeftShift");
 function blahblah()
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 Benproductions1 · Jun 08, 2014 at 09:26 AM 0
Share

"noob" is not an appropriate tag. How about ins$$anonymous$$d of checking whether two buttons are pressed down, check whether one button is pressed down and another button is also pressed down.

1 Reply

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

Answer by zharik86 · Jun 08, 2014 at 09:28 AM

I think, change your code to

  if(Input.GetKey("W") && Input.GetKey("LeftShift")) {
   //this is your function blahblah
  }
Comment
Add comment · Show 5 · 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 Burla · Jun 08, 2014 at 09:35 AM 1
Share

$$anonymous$$eep in $$anonymous$$d that this way the function blahblah will be called as long as you're holding down 'W' and 'LeftShift'. If for instance you hold those two buttons down for 1 second you would've called the function blahblah as many times as the FPS is. If you change it to Input.Get$$anonymous$$eyDown you'll have to lift the key to execute the function blahblah again. :-)

avatar image zharik86 · Jun 08, 2014 at 11:42 AM 1
Share

@Burla Yes, certainly you are right. But I wrote it as an example for understanding. If to be exact, it is possible to enter bool variable:

  private bool go = false;

  void LateUpdate() {
   if(Input.Get$$anonymous$$ey("W") && Input.Get$$anonymous$$ey("LeftShift")) {
    if (!go) {
     go = true;
     //your function
    }
   }
   if(Input.Get$$anonymous$$eyUp("W")) {
    go = false;
   }
  }

Or use Get$$anonymous$$eyDown, how you say.

avatar image Burla · Jun 08, 2014 at 06:47 PM 1
Share

I had no offensive intentions when I made this comment, don't doubt me. I just thought that this was a useful input to have in $$anonymous$$d. :-)

avatar image zharik86 · Jun 08, 2014 at 07:11 PM 1
Share

@Burla Simply, that you wrote is suitable for the majority of cases. But, for example, won't be suitable for relocation of the character when he changes from a step to run. In this case it is necessary to check key press always:)

avatar image CrilleStyles · Jun 09, 2014 at 01:19 PM 0
Share

this looks great. I will try both scripts to see what I like more!

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

24 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

Related Questions

Animation Not playing? (Noob) 1 Answer

If I let shift go restore fov 1 Answer

Changing Rate of Change from Key Key Input Values 1 Answer

access Input.GetButton key name 1 Answer

[ASNWERED] How To Change Button To An Alphabet Key 2 Answers


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