How i can make a jump delay in this script?
private void Update()
{
if (!m_MouseLook.mIsPaused)
Crouching = inputManager.GetButtonDown("Crouch");
anim.SetBool("crouch", Crouch);
RotateView();
// the jump state needs to read here to make sure it is not missed
if (!m_Jump && !m_onLadder)
{
if(!m_MouseLook.mIsPaused)
m_Jump = inputManager.GetButtonDown("Jump");
}
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded && !m_onLadder)
{
m_MoveDir.y = 0f;
m_Jumping = false;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_MoveDir.y = 0f;
}
if (isSwimming && inputManager.GetButton("Jump"))
m_MoveDir.y = 2.5f;
m_PreviouslyGrounded = m_CharacterController.isGrounded;
if (m_onLadder)
{
StopAllCoroutines();
rigidbody.useGravity = false;
rigidbody.isKinematic = true;
LadderUpdate();
}
else
{
LadderObject = null;
rigidbody.useGravity = true;
rigidbody.isKinematic = true;
}
}
private void FixedUpdate()
{
float speed;
GetInput(out speed);
if (!m_onLadder)
{
// always move along the camera forward as it is the direction that it being aimed at
Vector3 desiredMove = transform.forward * m_Input.y + transform.right * m_Input.x;
// get a normal for the surface that is being touched to move along it
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height / 2f);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
m_MoveDir.x = desiredMove.x * speed;
m_MoveDir.z = desiredMove.z * speed;
if (m_CharacterController.isGrounded)
{
if (Crouching)
OnCrouch();
m_MoveDir.y = -Stats.m_StickToGroundForce;
if (m_Jump)
{
rigidbody.velocity = new Vector3(0,0,0);
if (Crouch)
OnCrouch();
else
{
m_MoveDir.y = Stats.m_JumpSpeed;
m_Jump = false;
m_Jumping = true;
}
}
}
else
{
if (Crouch)
OnCrouch();
m_MoveDir += Physics.gravity * Stats.m_GravityMultiplier * Time.fixedDeltaTime;
}
m_CollisionFlags = m_CharacterController.Move(m_MoveDir * Time.fixedDeltaTime);
}
if (Crouch &&!isSwimming)
{
Stats = CrouchStats;
}
else
{
Stats = saveStats;
}
}