Hello, I've been trying to give my building health instead of my player, but it doesn't work.
Here is my script:
var explosion : GameObject;
var lives:
int;
function
OnTriggerEnter(otherObject:Collider)
{
if(otherObject.gameObject.tag ==
"Enemy")
{
lives --;
}
if
(lives <= 0)
{
var temp = Instantiate(explosion);
temp.transform.position = transform.position;
Destroy(gameObject);
}
}
function Update ()
{
}
function
OnGUI() {
GUI.Label(Rect(10,30,200,50), "Lives:
" + lives); }
Have you turn on "trigger" of your house in Inspector?
I get no errors, it's the house that doesn't lose health.
Hello Frank,
Plese try that.
var explosion : GameObject;
var lives: int = 100;
function OnTriggerEnter(otherObject:Collider)
{
if(otherObject.gameObject.tag == "Enemy")
{
lives --;
}
if (lives <= 0)
{
var temp = Instantiate(explosion);
temp.transform.position = transform.position;
Destroy(gameObject);
}
}
function Update ()
{
}
function OnGUI() { GUI.Label(Rect(10,30,200,50), "Lives: " + lives.ToString()); }
Regards