NullReferanceException When Enemy touches Player

Hello - Will here,
After creating a short script (supplied bellow) I have noticed an error occurring:
When the enemy touches the player, rather than taking the 10 health away, an error message is broadcasted; “NullReferanceException: Object Referance not set to an instance of an object.”
I am assuming this is what is stopping the health from being taken away.
Many Thanks, Will.

var health = 100;

var healthcount : Transform;

var enemy : Transform;

function Update () {

    healthcount.transform.GetComponent.<TextMesh>().text = health.ToString();

}

function OnTriggerEnter (other : Collider) {

    if (other.Collider.enemy){
	health -= 10;
    }

}

Hey BadwolfX

i believe it may be that you have not set the within your healthcount.transform.GetComponent.().text = health.ToString().

Because you are getting the component in Update, it is likely not available yet.

Instead cache this reference in Start so you dont get it each time.

Like this:

     Text healthText;

void Start()
{
healthText = healthcount.transform.GetComponent.<TextMesh>();
}

void Update()
{
healthText.text = health.ToString();
}