Calculate distance between player and floor

I’m making a game in which the player is free falling. I want the player to know how much time they have left until they hit the floor. Currently I’m calculating the distance between the player and the floor as in the script below. This doesn’t give me the actual distance between the player and the floor though as the calculation for “floorDist” continues even whilst the player is on a static ledge above the ground, or stood on the ground. Any advice on how to better calculate this distance would be appreciated.

	public GameObject floor;
	public float floorDist;
	
	void Awake () 
	{
		floorDist = gameObject.transform.position.y;

	}
	
	void Update()
	{
		FloorMeasure();
		floorDist = gameObject.transform.position.y;
	}
	
	void FloorMeasure()
	{
		floorDist = gameObject.transform.position.y - floor.transform.position.y;
	}

You can use linecast Unity - Scripting API: Physics.Linecast

Then access the distance of the hit Unity - Scripting API: RaycastHit

Look up on what code is used to see if a character can jump. you can use much of the same code.

Hi, you must use Raycast, it is simple and usefull !