Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to check for 2 pressed keys?

Discussion in 'Scripting' started by SonicX278, Nov 28, 2015.

  1. SonicX278

    SonicX278

    Joined:
    Nov 25, 2015
    Posts:
    3
    So in my game the player can walk and he can run. To walk you press "W" but for running you need to press "LeftShift+W" and i cant get the code figured out to check if shift was pressed and W at the same time.

    --SonicX278
     
  2. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    check if w is true and shift false then walk, else if both are true then run
     
  3. LiberLogic969

    LiberLogic969

    Joined:
    Jun 29, 2014
    Posts:
    138
    Code (CSharp):
    1. if(Input.GetKeyDown(Keycode.W) && Input.GetKeyDown(Keycode.LeftShift))
    2. {
    3.     // run
    4. }
    5. else if(Input.GetKeyDown(Keycode.W)
    6. {
    7.     // walk
    8. }
    9.  
     
    Last edited: Nov 28, 2015