Question by 
               NGN · Aug 23, 2015 at 02:28 PM · 
                double jump  
              
 
              Please help me with my double jump error
I seem to be making the code more complex with every try so please help me fix this, i just want to call the double jump once and disable it until grounded. thanks using System.Collections; using UnityEngine;
public class PlayerController : MonoBehaviour {
 private bool Jump;
 private bool DJ = false;
 private bool CanDj = false;
 private bool Grounded;
 public float Speed = 2f;
 public float JumpForce = 5f;
 public GameObject PlayerObj;
 public GameObject GroundObj;
 void OnCollisionEnter2D(Collision2D other)
 {
     if (GroundObj.gameObject.CompareTag("Ground"))
     {
         print("Grounded");
         Grounded = true;
         DJ = false;
         Jump = false;
     }
 }
   
 void Update()
 {
     if (Jump)
     {
         CanDj = true;
             if (Input.GetMouseButton(0) && !DJ && CanDj)
             {
                 DJ = true;
             }
     }
 }
 
 void FixedUpdate()
 {
     PlayerObj.rigidbody2D.velocity = new Vector2(Speed, rigidbody2D.velocity.y);
     if (Input.GetMouseButton(0) && Grounded)
     {
             rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0f);
             PlayerObj.rigidbody2D.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Impulse);
             Grounded = false;
             Jump = true;
              CanDj = true;
             print("jumping");
     }
     else if (Input.GetMouseButton(0) && DJ && CanDj)
     {
         rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 0f);
         PlayerObj.rigidbody2D.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Impulse);
         print("Doublejumping");
         CanDj = false;            
     }
 }
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Double Jump Not Working Good 1 Answer
Double Jump Unity 1 Answer
need help with double jump? 0 Answers
Player not double jumping. 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                