Hi, I'm writing a code for my platformer game .I have an issue with double jump .When I jump after 3 jump I'm not able to jump anymore also when I collide with object in scene. My code is: Code (CSharp): using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { public float moveSpeed; public float jumpHeight; private Rigidbody2D rigi; public Transform groundCheck; public float groundCheckRadius; public LayerMask whatIsGround; private bool grounded; private bool doubleJumped; // Use this for initialization private void Awake() { rigi = GetComponent<Rigidbody2D>(); } void Start () { } void FixedUpdate () { grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius,whatIsGround); } // Update is called once per frame void Update () { if (grounded) doubleJumped = false; if(Input.GetKeyDown (KeyCode.Space) && grounded) { //rigi.velocity = new Vector2(rigi.velocity.x, jumpHeight); Jump (); } if(Input.GetKeyDown (KeyCode.Space) && !doubleJumped && !grounded) { //rigi.velocity = new Vector2(rigi.velocity.x, jumpHeight); Jump(); doubleJumped=true; } if(Input.GetKey (KeyCode.RightArrow)) { rigi.velocity = new Vector2(moveSpeed, rigi.velocity.y); } if(Input.GetKey (KeyCode.LeftArrow)) { rigi.velocity = new Vector2(-moveSpeed, rigi.velocity.y); } } public void Jump(){ rigi.velocity = new Vector2(rigi.velocity.x, jumpHeight); } } Thanks
Is it ALWAYS after 3 jumps? Doesn't seem to be any issue with your code. All I can think of is that maybe your groundCheck.position isn't hitting your ground properly, so it's not setting doubleJumped back to false. Trying doing a Debug.Log(doubleJumped); on your Update function - this will output the value of doubleJumped to the console window, and see if doubleJumped is being properly set back to false every time.