Hi,
I’ve written a script that allows my character to fly if not grounded (kind of like a double jump) as long as the “w” key is held down and the “flytime” variable is above zero, which works exactly how i’d like. The one problem is that as long as flytime is above zero, the player can press “w” any amount of times and cause the function to do its thing. I’d like it only to be able to be pressed once, but I just can’t figure out the logic. heres the code (I’ve omitted all the particle effects, audio and physics commands):
void FixedUpdate ()
{
if (Input.GetKey (KeyCode.W) && flytime > 0f && !IsGrounded)
{
HandleFlyTime ();
IsFlying = true;
}
else
{
IsFlying = false;
}
}
void HandleFlyTime ()
{
flytime -= 2.5f * Time.deltaTime;
}
Thanks!!!