Accessing an Variable of a Script with Raycast ( JS )

Hello Community,

im testing this for a while now but i dont know. I have the feeling i did a stupid little mistake, because its not working.

I have the Script on my Player:

function Update ()
{

var enemyHealth : int;
var hit : RaycastHit;

Debug.Log(enemyHealth);

	if(Physics.Raycast(transform.position, transform.forward, hit, 100))
	{
		if(hit.collider.gameObject.tag == "Enemy")
		{
			Debug.Log("Got an Enemy");
			var enemyLifeScript = hit.transform.GetComponent("EnemyHealth");
			test = enemyLifeScript.Health;
		}
	}

}

and the Script on the Enemy called “EnemyHealth” which is for testing only 1 line:

public var Health = 1000;

What i want is, that i get the enemyHealth variable. Its not working :frowning:
The Console shows me that i hit the enemy, but the enemyHealth is always still 0.

Its written in JS.

Thanks for your help :slight_smile:

var enemyLifeScript : EnemyHealth = hit.transform.GetComponent(“EnemyHealth”) as EnemyHealth;
test = enemyLifeScript.Health;