I have been making a 2D game in Unity, with a group of mine. We have made a character and are able to make him run and jump. Currently, I have been trying to make him double jump so someone can't just spam the jump button and go flying, but nothing has been working.
I've been through about at least 10 different tutorials on it, but nothing has worked. How do I make my character double jump?
public float speed;
public float jump;
float moveVelocity;
private Rigidbody2D myRigidBody;
private bool grounded = true;
void Start ()
{
myRigidBody = GetComponent<Rigidbody2D> ();
}
void Update ()
{
//constant run
myRigidBody.velocity = new Vector2(speed, myRigidBody.velocity.y);
if (Input.GetKeyDown (KeyCode.Space))
{
if (grounded)
{
myRigidBody.velocity
= new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jump);
}
}
}