title: Unity 2D Jump script
body: <p>So I was trying to implement double jumping in my game, which doesn't work. And now, somehow, not only can't  my players double jump, they can't even jump either!</p>
  
  <p>update: they can jump now, still can't double jump though.</p>
  
  <p>This is my whole movement script:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using UnityEngine;
  
  namespace Players
  {
      public class Actor : MonoBehaviour
      {
          //in order to control both players using 1 script.
          public int playerIdx;
  
          //Variables.
          public float movementSpeed = 150f;
          public float jumpForce = 250f;
  
          //Ground stuff.
          public LayerMask whatIsGround;
          public bool grounded;
  
          //boolean stuff.
          private bool facingRight;
          private bool moving;
  
          //Needed to check if player is on the ground.
          public Transform groundCheck;
  
          //Limit player's movement speed.
          public float maxMovementSpeed = 400f;
  
          //Double jump stuff.
          private bool doubleJumpReady;
  
          //rb
          private Rigidbody2D rb;
  
  
          // Start is called before the first frame update
          void Start()
          {
              doubleJumpReady = true;
              rb = GetComponent&lt;Rigidbody2D&gt;();
              facingRight = true;
          }
  
          // Update is called once per frame
          void FixedUpdate()
          {
              SlowDown();
          }
  
          private void LateUpdate()
          {
              grounded = Physics2D.OverlapCircle(groundCheck.position, 0.1f, whatIsGround);
  
              if (grounded)
                  doubleJumpReady = true;           
  
          }
  
          private void SlowDown()
          {
  
              if (moving) return;
  
              //if player is not moving, slow them down.
              if (rb.velocity.x &gt; 0.2f)
                  rb.AddForce(movementSpeed * Time.deltaTime * -Vector2.right);
              if (rb.velocity.x &lt; -0.2f)
                  rb.AddForce(movementSpeed * Time.deltaTime * Vector2.right);
          }
  
          public void Move(int dir)
          {
              //Flip the player.
              Flip(dir);
  
              //Moving the player.
              moving = true;
  
              float xVel = rb.velocity.x;            //Get x velocity.
  
              if ( dir &gt; 0)
                  rb.AddForce(movementSpeed * Time.deltaTime * Vector2.right * dir);
              else if (dir &lt; 0)
                  rb.AddForce(movementSpeed * Time.deltaTime * Vector2.right * dir);
              else if (dir == 0) { }  //do nothing.
  
              //Help player turn around faster.
              if (xVel &gt; 0.2f &amp;&amp; dir &lt; 0)
                  rb.AddForce(movementSpeed * 3.2f * Time.deltaTime * -Vector2.right);
              if (xVel &lt; 0.2f &amp;&amp; dir &gt; 0)
                  rb.AddForce(movementSpeed * 3.2f * Time.deltaTime * Vector2.right);
          }
  
          private void Flip(int dir)
          {
              if (facingRight &amp;&amp; dir == -1 || !facingRight &amp;&amp; dir == 1)
              {
                  facingRight = !facingRight;
                  transform.Rotate(0f, 180f, 0f);
              }
          }
  
          protected void Jump()
          {
              if (grounded)
              {
                  rb.AddForce(Vector2.up * jumpForce);
                  grounded = false;
                  doubleJumpReady = true;
              }
              else if (!grounded &amp;&amp; doubleJumpReady)
              {
                  rb.AddForce(Vector2.up * jumpForce);
                  doubleJumpReady = false;
              }
          }       
      }
  }
  
  
  </code></pre>
  
  <p>I don't know if it is because of my jump script, or my player script:</p>
  
  <pre class="lang-cs prettyprint-override"><code>void Update()
  {
      if (playerIdx == 1)
      {
          if (Input.GetKey(KeyCode.A))
              Move(-1);
          if (Input.GetKey(KeyCode.D))
              Move(1);
          if (Input.GetKey(KeyCode.W))
              Jump();
      }
  
      if (playerIdx == 2)
      {
          if (Input.GetKey(KeyCode.LeftArrow))
              Move(-1);
          if (Input.GetKey(KeyCode.RightArrow))
              Move(1);
          if (Input.GetKey(KeyCode.UpArrow))
              Jump();
      }
  }
  </code></pre>
  
  <p>So how can I fix this?</p>