Hello, i was wondering how i could implement a sort of delay into my game so that after the user jumps, they cant immidiately jump straight after. My game is all in the air so i have no onGround or grounded function, and i just need to know how i would make it so that there is a delay in between jumps. I hope it make sense and thank you
My Code:
using UnityEngine;
using System.Collections;
public class NewJump : MonoBehaviour {
public int jumpHeight;
float jumpSpeed;
Vector3 velocity;
void Start(){
jumpSpeed = Mathf.Sqrt(-2*Physics.gravity.y*jumpHeight) + 0.1f;
}
void Update(){
if (Input.GetMouseButtonDown(0)){
velocity = rigidbody.velocity;
velocity.y = jumpSpeed;
rigidbody.velocity = velocity;
}
}
I had used a “timer” to let the addforce work otherwise the character has no time to jump because update start every frame. (timer>5 works fine for me and the delay is 1 sec). This is my code:
private float jumpDelay=1f;
public bool jumped;
public int timer;