Hi all. I'm a total programing noob, and This script wont work. The idea is, when the health <= 0, he it should Destroy Object. However, nothing happens, and the Health counter simply goes negative, forever... Any ideas? Thanks in advance.
var destroyedPrefab : GameObject;
var destroyedPrefabfx : GameObject;
var health : int = 3;
private var damage : int = 1;
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.tag=="Enemy")
{
health -= damage;
}
}
function update (){
if(health <= 0)
{
Destroy(gameObject);
Instantiate(destroyedPrefab, transform.position, transform.rotation);
Instantiate(destroyedPrefabfx, transform.position, transform.rotation);
var guiText = GameObject.Find("GUI Text").GetComponent(GUIText);
guiText.text = myNiceVariable;
}
}
↧