When Ever I jump, It only jumps once, after that it does not allow me to jump again.
using UnityEngine;
using System.Collections;
public class Runner : MonoBehaviour {
public bool grounded = true;
public float jumpPower = 190;
private bool hasJumped = false;
public float Speed;
// Use this for initialization
void Start () {
transform.Translate (Vector3.left * Time.deltaTime * Speed);
}
// Update is called once per frame
void Update () {
// Do something
if(!grounded && GetComponent<Rigidbody>().velocity.y == 0) {
grounded = true;
}
if (Input.GetKeyDown(KeyCode.Space) && grounded == true) {
hasJumped = true;
}
}
void FixedUpdate (){
if(hasJumped){
GetComponent<Rigidbody>().AddForce(transform.up*jumpPower);
grounded = false;
hasJumped = false;
}
}
}