i need to access a variable from another game object. what i wan’t to happen is have a variable called kills go up by 1 every time the dead function is called by the script controlling the enemy prefab. here’s my script(javascript).
Health script for enemy:
var Health : int = 1;
var Type1Damage : int = 1;
var Type2Damage : int = 5;
var Type3Damage : int = 10;
var Blood : Transform;
function Start ()
{
}
function LateUpdate()
{
if(Health <= 0)
{
Health = 0;
Dead();
}
}
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Type 1")
{
Health -= Type1Damage;
}
if(collision.gameObject.tag == "Type 2")
{
Health -= Type2Damage;
}
if(collision.gameObject.tag == "Type 3")
{
Health -= Type3Damage;
}
}
function Dead()
{
Destroy(gameObject);
Instantiate(Blood, transform.position, transform.rotation);
}
GUI script for camera:
public var Kills : int = 0;
function Update ()
{
}
function OnGUI()
{
GUI.Label(Rect(Screen.width / 2, 10, 60, 20), "" + Kills);
}