title: Hi, how can i stop my 2D character to stop jumping in the air?
body: <p>He will jump always when i press the jump button. I hope you can help me guys. This is my first game so, i dont know that much. This is my code:</p>
  <pre><code>Rigidbody2D rb;
  float dirX;
  float jumpForce = 300f;
  private bool canJump = false;
  private bool hasSwitchedLayers = false;
  public Transform Teleport1;
  private Vector3 startPos;
  
  void Start()
  {
      startPos = new Vector3(-10, 1.5f, 0);
      rb = GetComponent&lt;Rigidbody2D&gt;();  
  }
  
  void Update()
  {
      dirX = CrossPlatformInputManager.GetAxis(&quot;Horizontal&quot;);
      rb.velocity = new Vector2(dirX * 10, rb.velocity.y);
  
      if (CrossPlatformInputManager.GetButtonDown(&quot;Jump&quot;) )
      {
          rb.AddForce(new Vector2(rb.velocity.x, jumpForce), ForceMode2D.Force);  
      }
  }
  </code></pre>