You are on page 1of 1

void Update()

{
if (Input.GetKeyDown(KeyCode.Space))
{
// Code executed every frame when Space is pressed
}
}
You can make it a little bit better by binding keys and axes with names in Project
Settings > Input Manager to then write your script like this instead:

{
if (Input.GetKeyDown("Jump"))
{
// Code executed every frame when key bound to "Jump" is pressed
}
}
And when you want to read values from the axes, you can do it like this:

void Update()
{
float verticalAxis = Input.GetAxis("Vertical");
float horizontalAxis = Input.GetAxis("Horizontal");

// Do something with the values here


}

You might also like