I had to use an arbitrary class name/file name of PlayerFallManager since you did not provide one, but here is your code converted. Change the name to what you like (file name and class name must match)
using UnityEngine;
using System;
public class PlayerFallManager : MonoBehaviour
{
public float lastPositionY = 0f;
public float fallDistance = 0f;
public Transform player;
CharacterController controller;
public float currentHealth = 10.0f;
public void Start()
{
controller = GameObject.Find("First Person Controller").GetComponent<CharacterController>();
}
public void Update()
{
if(lastPositionY > player.transform.position.y)
{
fallDistance += lastPositionY - player.transform.position.y;
}
lastPositionY = player.transform.position.y;
if(fallDistance >= 5 && controller.isGrounded)
{
currentHealth -= 5.0f;
ApplyNormal();
}
if(fallDistance <= 5 && controller.isGrounded)
{
ApplyNormal();
}
}
public void ApplyNormal()
{
fallDistance = 0.0f; lastPositionY = 0.0f;
}
public void OnGUI()
{
GUI.Box(new Rect(10.0f, 20.0f, 50.0f, 20.0f),"" + currentHealth);
}
}