0
I need him to execute the command to fly for a certain period.
Example: The character has a jetpack, if you press the "space" key twice it will activate the flight code, only the astronaut only you can fly for 5 seconds and then stop flying.
This is the code
if (canFly && Input.GetKey(KeyCode.Space))
{
//Voando
GetComponent<Animator>().SetBool("flying", true);
rigidbody.velocity = new Vector2(rigidbody.velocity.x,+2.5f);
}
else
{
GetComponent<Animator>().SetBool("flying", false);
}
Wouldn’t just be you logging the moment the player pressed the space key and see if it’s past the 5s?
– Leandro Angelo
I don’t know how to get the keys in Unity but I imagine it’s something like this: In the event 'Onkeydown' if it’s space starts a timer for 5s. In the event 'Onkeyup' if space cancels the timer. In the event 'Ontimer' starts the flight and cancels itself.
– Augusto Vasques