It only lets me jump once when I first press Space but then not again. Not sure what to change really so any help would be greatly appreciated.
public bool grounded = true;
public float jumpPower = 190;
public bool jumpCooldown = false;
private bool hasJumped = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (!grounded && GetComponent<Rigidbody>().velocity.y == 0)
{
grounded = true;
}
if (Input.GetKey (KeyCode.Space) && grounded == true && jumpCooldown == false)
{
hasJumped = true;
jumpCooldown = true;
}
}
void FixedUpdate()
{
if (hasJumped)
{
GetComponent<Rigidbody>().AddForce(transform.up*jumpPower);
grounded = false;
hasJumped = false;
}
}
IEnumerator jumping()
{
for (int x = 1; x < 2; x++)
{
yield return new WaitForSeconds (5);
jumpCooldown = false;
}
}
}