Component.GetComponent Problem

My issue is that im trying to call the variable enemy health from my enemy script inside of another script and I cant make it a static variable because multiple enemies use that script. Im trying to use Component.GetComponent but i keep getting the error
Assets/TankMan/TankManScripts/Items_Objects/AmmoHolder.js(1,15): BCE0018: The name ‘Component.GetComponent.Turret.enemyhealth’ does not denote a valid type (‘not found’).

I know i could just put this script inside of my Turret script but im trying to understand how to use getcomponent.

var eHealth : Component.GetComponent.Turret.enemyhealth;
var parts : GameObject;
function Update () {
		if (Turret.ehealth <=0) {
		Instantiate(parts, transform.position ,transform.rotation);
		}
}

That isn’t how you use get component. Take a look at this perhaps.
http://unity3d.com/support/documentation/ScriptReference/Component.GetComponent.htmlSo if you have a component named turret. Just do this.

var turretHealth : int;
var parts : GameObject; 

function Start()
{
    turret = GetComponent("Turret").enemyhealth;
}

function Update () 
{     
    if (Turret.ehealth <=0) 
    {         
        Instantiate(parts, transform.position ,transform.rotation);
    } 
}

Try this. Haven’t tried but do show how get component works. :smile:

Nvm I figured it out.

var parts : GameObject;
function Update () {
	var turret : Turret;
	turret = GetComponent (Turret);
	ehealth = turret.enemyhealth;
		if (ehealth <=0) {
		Instantiate(parts, transform.position ,transform.rotation);
		Debug.Log ("Dropped Ammo");
		}
}

Nvm I figured it out.

var parts : GameObject;
function Update () {
	var turret : Turret;
	turret = GetComponent (Turret);
	ehealth = turret.enemyhealth;
		if (ehealth <=0) {
		Instantiate(parts, transform.position ,transform.rotation);
		Debug.Log ("Dropped Ammo");
		}
}