Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two keys, same function

Tags:

c#

I just started coding yesterday however, I have ran into this issue and however much I google I can't seem to find the right answer.

if(Input.GetKey(KeyCode.D)) || if(Input.GetKey(KeyCode.RightArrow))
{
    target_right = new Vector2(transform.position.x + right_increment, transform.position.y);
    transform.position = target_right;

}

I have read online that || in plain English means or. I want both button D and the right arrow button to execute the code. How do I do this?

like image 543
realFishSam Avatar asked Apr 22 '26 23:04

realFishSam


1 Answers

Your syntax should look like this

if( Input.GetKey(KeyCode.D) ||Input.GetKey(KeyCode.RightArrow))
{
    target_right = new Vector2(transform.position.x + right_increment, 
    transform.position.y);
    transform.position = target_right;
}
like image 164
Adas Avatar answered Apr 24 '26 13:04

Adas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!