How I would manage this is to determine when they transition to the Falling state and note the Transform Y position for the current height. Then on collision, I would calculate the damage based upon fall distance.
Your scripts look like you have just started throwing code at the problem without doing any research. I would suggest you look into State Machines and Character Controllers.
https://game-developers.org/how-to-make-a-state-machine-character-controller-advanced-unity-tutorial/
Dapper Dino is using Visual Scripting to illustrate the concept. I would suggest this will help you understand the process.
It does not have to be as complex as illustrated for example here is my boilerplate code to manage the states of my player character.
private PlayerState GetState()
{
return state;
}
/// <summary>
/// Description:
/// Sets the player's current state
/// Input:
/// none
/// Return:
/// void (no return)
/// </summary>
/// <param name="newState">The PlayerState to set the current state to</param>
private void SetState(PlayerState newState)
{
state = newState;
}
/// <summary>
/// Description:
/// Determines which state is appropriate for the player currently
/// Input:
/// none
/// Return:
/// void (no return)
/// </summary>
private void DetermineState()
{
if (playerHealth.currentHealth <= 0)
{
SetState(PlayerState.Dead);
}
else if (grounded)
{
if (playerRigidbody.velocity.magnitude > 0)
{
SetState(PlayerState.Walk);
}
else
{
SetState(PlayerState.Idle);
}
if (!jumping)
{
timesJumped = 0;
}
}
else
{
if (jumping)
{
SetState(PlayerState.Jump);
}
else
{
SetState(PlayerState.Fall);
}
}
}
You are conceptually missing whole sections of the process, and I would suggest that you examine this course
https://www.coursera.org/learn/game-design-and-development-2
It is specific to 2d platformers, to be fair I would start with the first course in the series which is a 2d space shooter game.
You can sign up for free get all the code assets and parts and then decide if you want to pay the 60 odd dollars to complete it.