Both Jump and Double jump are getting executed, could somebody please help me?
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public float JumpForce = 5f;
private bool isJumping = false;
private bool isJumping2 = false;
public GameObject PlayerObj;
public GameObject GroundObj;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
//Jumping Section
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButton(0))
{
if (isJumping == false)
{
PlayerObj.rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0f);
PlayerObj.rigidbody2D.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Impulse);
isJumping = true;
print("Jump");
}
else if (!isJumping2)
{
PlayerObj.rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0f);
PlayerObj.rigidbody2D.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Impulse);
isJumping2 = true;
print("Double Jump");
}
}
}
//this bit is to check if the object that collided with it has the ground tag
void OnCollisionEnter2D(Collision2D other)
{
if (GroundObj.gameObject.CompareTag("Ground"))
{
isJumping = false;
isJumping2 = false;
print("Ground");
}
}
}