title: I'm trying to get my cube to only jump on the ground but my if statement isn't working
body: <pre><code>public Rigidbody rb;
  public bool cubeIsOnTheGround = true;
  public float speed = 10;
  
  Vector3 direction;
  
  // Start is called before the first frame update
  void Start()
  {
      rb.GetComponent&lt;Rigidbody&gt;();
  }
  
  // Update is called once per frame
  void Update()
  {
      Vector3 input = new Vector3(Input.GetAxisRaw(&quot;Horizontal&quot;), 0, Input.GetAxisRaw(&quot;Vertical&quot;));
      direction = input.normalized;
      
      if (Input.GetButtonDown(&quot;Jump&quot;))
      {
          rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
      }
  
      if (cubeIsOnTheGround == true)
      {
          if (Input.GetButtonDown(&quot;Jump&quot;))
          {
              rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
              cubeIsOnTheGround = false;
          }
      }
  }
  
  void FixedUpdate()
  {
      rb.position += direction * speed * Time.deltaTime;
  }
  
  void OnCollisionEnter(Collision collision)
  {
      if (collision.gameObject.CompareTag(&quot;Ground&quot;))
      {
          cubeIsOnTheGround = true;
      }
  }
  </code></pre>
  <p>The if statemnt boolIsOnTheGround is not working. What I'm trying to do is check whether the cube is on the ground so I kno when you can jump. The cube just bounces infinitely by pressing space.</p>