Home > Back-end >  Changing a If button press to a if button not pressed
Changing a If button press to a if button not pressed

Time:10-27

I know this is a very stupid question and very easy for most people to answer, but this is what I have so far:

if (Input.GetKey(KeyCode.LeftArrow))
    {
        rotation  = speed * Time.deltaTime; 
    }

I know that is is something to do with a "!" but not sure where to put it.

And i would also like to know how to put it into this context:

        if ((Input.GetKey(KeyCode.RightArrow)) && ((Input.GetKey(KeyCode.RightArrow))))
    {
        if (transform.eulerAngles.z < 0){
        rotation  = speed * Time.deltaTime;     
       }
    }

And I would like to check that both of them are not pressed.

CodePudding user response:

I need more information about the question you want to ask. Based on the information you've provided so far, my advice is:

if (!Input.GetKey(KeyCode.LeftArrow))
{
    rotation  = speed * Time.deltaTime; 
}

CodePudding user response:

I'm not familiar with unity but assuming function names and enums are correct then this should trigger when it's not the right or left arrow that is pressed (in your example you used RightArrow twice).

Your IDE should let you know about syntax errors though.

if (!Input.GetKey(KeyCode.RightArrow) && !Input.GetKey(KeyCode.LeftArrow)) {
  if (transform.eulerAngles.z < 0) {
    rotation  = speed * Time.deltaTime;     
  }
}
  • Related