- Home /
House/building losing health
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); }
Answer by Franky 1 · May 16, 2011 at 08:40 AM
I get no errors, it's the house that doesn't lose health.
Answer by Grcan SERBEST · May 16, 2011 at 09:03 AM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613134400im_/https://answers.unity.com/themes/thub/images/avi.jpg)