I sense a stupid question
#pragma strict
var Life : int = 15;
function OnTriggerEnter(other : Collider)
{
Life--;
Debug.Log("Life = " + Life);
//if(life <= 0)
//{
// Destroy(other.gameObject);
//}
}
I keep resulting in 14. I feel like I am missing something stupid.
you need to ask a question, the code you posted will give 14 since you are assigning Life a value of 15 then subtracting 1 from it.
OnTriggerStay(other : Collider)
is what you're looking for
each enter is supposed to subtract 1 and it does but ends up resetting to 15. it is supposed to go 14 - 13 - 12 ... decreasing 1 every time it is hit. OnTriggerStay seems to count only those in the bubble; I think 10 was the lowest I got it with my oversize test balls. Now that I am realizing there are multiple trigger types I'm guessing that I am just using the wrong one to increment hits.
Answer by pyromaniac511 · Sep 10, 2015 at 01:12 AM
I had to make the variable static
static var Life : int = 15
Seems odd to me, I thought static variables didn't change.