- Home /
Lives bring down too fast
I've written a script in order to lower a life for every collision with a trigger but when the player enters to a trigger the lives bring down extremely fast.
The scrip that i`ve written is that:
var Vida = 3;
function OnTriggerEnter2D (collision : Collider2D)
{
if(collision.transform.name == ("Finish"))
{
Vida -= 1;
}
Which is the mistake?
PD: I also want to lower a life when colliding with an specific tag, not a name, but I don't know what I have to write...
Thank You
Answer by YoungDeveloper · May 04, 2014 at 02:53 PM
Hi, it lowering super fast because it's executed every frame it's touching. There had been tens of similar cases, please try google searching before asking: http://answers.unity3d.com/questions/633254/how-to-call-ontriggerenter-once.html
And to check tag, create a new tag in tags list first, and in code it's something like this.
if(collision.tag == "Finish"){
//code
}
To create tag: https://www.youtube.com/watch?v=5UA3TjRPjcw