I have the follwing part of a character controller code. The problem is that I have to press the jump button the hole time to perform a full jump. How i can make it, so when i press Space one time,it makes the whole jump?
var jumpDelay : boolean;
var doubleJump : int = 0;
function Update()
{
if( Input.GetKeyDown(KeyCode.Space) && jumpDelay == false)
{
Jump();
}
}
function Jump()
{
if (doubleJump <= 1)
{
rigidbody.velocity.y = 175;
jumpTimer();
}
}
function jumpTimer()
{
if (Input.GetKeyDown(KeyCode.Space))
{
doubleJump ++;
}
if (doubleJump > 1)
{
doubleJump = 0;
jumpDelay = true;
yield WaitForSeconds(3);
jumpDelay = false;
}
}
Make sure you have a rigid body attached to your character when you do this. I will write you a jump timer now so that the player cannot jump repeatedly, unless that’s what you want?