Grounded Bool help

HI
Need some help with a Grounded booleon i am using.

The code basically checks with a raycast if the player is on the floor.
The code works on the initial run and sets isgrounded to true. However when i jump the bool isnt being activated again. Anyone got any help how i make the isgrounded bool run again to check if the player is on teh floor.?

Here is the code. :

   public bool isGrounded {
     get {
       Vector3 position = transform.position;
       Debug.Log ("YO");
       position.y = GetComponent<Collider2D>().bounds.min.y + 0.1f;
       float length = isGroundedRayLength + 0.1f;
       Debug.DrawRay (position, Vector2.down * length);
       bool grounded = Physics2D.Raycast (position, Vector3.down, length);
       return grounded;
     }
   }

THis is set to TRUE when i start the game.

i then use the following line to prevent double jumping

if (Input.GetKeyDown (KeyCode.Space) && isGrounded == true) {

just need help on how to make the code check the public bool again.

Any help would be appreciated.

Thanks

every time you look for isGrounded unity will go through the isGrounded get { } code.

Oh right, so it should be doing that when my second line of code runs right?

if (Input.GetKeyDown (KeyCode.Space) && isGrounded == true) {

It’ll re-run all of the code in your GET every single time, yes. That’s how properties work.