I need to restrict the player’s ability to double jump. Right now I have jump height restricted by a timer, I need that timer to set itself to one, or the Jumping() function to turn itself off, if the key is released while the player is in the air.
if (Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.L))
{
if (moveHorizontal != 0)
{
timer += Time.deltaTime;
if (timer < jumpTime && isGrounded == true)
{
Jumping();
}
}
}
void Jumping()
{
objPlayer.AddForce(Vector3.up * jumpHeight);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Tile")
{
timer = 0f;
isGrounded = true;
}
}