What can i use instead of && to press two keys
else if (Input.GetKeyDown(“Vertical”)) && (Input.GetKeyDown(“e”))
TP_Motor.Instance.MoveVector = Vector3.zero;
What can i use instead of && to press two keys
else if (Input.GetKeyDown(“Vertical”)) && (Input.GetKeyDown(“e”))
TP_Motor.Instance.MoveVector = Vector3.zero;
GetKeyDown is true only in the frame the event occurs. And the likelihood that the user hit both e and a at the same exact instant is remote. Try this instead:
if ( (Input.GetKeyDown("Vertical")) && (Input.GetKey("e")) // e was down already, they just hit Vertical
|| (Input.GetKey("Vertical")) && (Input.GetKeyDown("e"))) // Vertical was down, they just hit e
{
.. do whatever ...
}
When using the && operator, it basically short cuts out of the if statement if the first part of it is true. So: else if (Input.GetKeyDown("Vertical"))
is true and the if statement will not check the rest of the condition.
What you can do is use one single & like so : else if(Input.GetKeyDown("Vertical")) & (Input.GetKeyDown("e"))
.
This should check BOTH conditions are true before accepting the entire IF statement is true.
also InputManager
and your code must be like this
else if (Input.GetButtonDown(“Vertical”)) && (Input.GetKeyDown(KeyCode.E))
TP_Motor.Instance.MoveVector = Vector3.zero;
I found that they work the same with && or & depending on the parenthesis.
else if (Input.GetKeyDown("e") && Input.GetKeyDown("a"))
this.transform.position += transform.right * transform.localScale.z;
else if (Input.GetKeyDown("e") & Input.GetKeyDown("a"))
this.transform.position += transform.right * transform.localScale.z;
Works the same