Script Not working... still

Hey guys so my Boss is sopose to have 10(or whatever I set to) lives. But this script I have created is not really doing this. It doesn’t say there is an error but it isn’t doing what the script is saying. Here is the script:

var NextL6 : Transform;
var BossHealth : int = 10; 
function Update ()
{
NextL6.renderer.enabled=false;
if (BossHealth == 0) 
{
Destroy(gameObject);
NextL6.renderer.enabled=true;
}
}
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == "wormProjectile") 
{ 
BossHealth--; //(or BossHealth -= 1, either would work fine) 
}
}

So basically I am having it at 10 hits then it will die. I also have a little thing in there that Hides the teleporter to my next level (you can ignore it, it is working fine). So I need a way to do what I’m trying to do up there (I might make it more like 15 hits or 20). Anyone have any idea why it is only taking one hit to kill?

Set it up like this: var bossHealth = 10.0; (you dont need the int ten for this)

then do something like:

if(TriggerisActivated)
{
bossHealth -= 1;
if(bossHealth == 0)
{play awesome death animation
}
}

:slight_smile:

I think the main problem is the fact that the if health == 0 is not in the same function as the health-- line…

This didn’t really work for me very well, maybe something else?

Try adding some debug output using Debug.Log(). Log a message when a hit is recorded and the health is decremented that shows what the current health value is. Also, log a message when 0 is reached and the object is destroyed. That should be a good first step towards figuring out what’s going wrong.

^^ not exactly sure what the debug option is and were to put it… im still very very new at this :stuck_out_tongue:

var NextL6 : Transform; 
var BossHealth : int = 10; 
function Update () 
{ 
NextL6.renderer.enabled=false; 
if (BossHealth == 0) 
{ 
Destroy(gameObject); 
NextL6.renderer.enabled=true; 
} 
} 
function OnTriggerEnter(hit : Collider) 
{ 
if(hit.gameObject.tag == "wormProjectile")
{ 
BossHealth--; //(or BossHealth -= 1, either would work fine);
} 
}

Maybe just take what I have so far and put what your talking about into it? Thanks