Reputation: 11
I'm a new programmer trying to make a game in Unity and I want to make an if statement that senses when the right arrow key is pressed. This has been working for me so far with letter keys:
if (Input.GetKey("d")) {
//Code would be here
}
I've looked, but I can't find anything that can replace the letter string so it senses the pressing of the right arrow button.
Upvotes: 1
Views: 1134
Reputation: 1037
Just want to add a little bit more information:
You can get three type of events on key pressed.
if (Input.GetKeyDown(KeyCode.RightArrow))
{
print("right Arrow key pressed");
}
if (Input.GetKeyUp(KeyCode.RightArrow))
{
print("right Arrow was released");
}
if (Input.GetKey(KeyCode.RightArrow))
{
print("right Arrow is held down");
}
Upvotes: 0
Reputation: 1
Check out bellow code for a right arrow key pressed detection. Put this code in Update()
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Debug.Log("right Arrow key pressed");
}
If you want to use other arrows, then use KeyCode.LeftArrow
, KeyCode.UpArrow
, KeyCode.DownArrow
Upvotes: 0
Reputation: 129
There is a list of Enum KeyCode.
What you need is KeyCode.RightArrow
.
You can see it in Unity Docs and also in the .NET API documentation
Upvotes: 3