- Home /
Question by
brenolimaa96 · Apr 25, 2016 at 08:40 PM ·
animationgameobjecttransformontriggerenteroncollisionenter
OnTriggerEnter2D only one time
How can I execute an OnTriggerEnter2D only one time in the scene?
I've made an animated checkpoint that when the player walks beside, it starts an animation, but i would like that this animation could only happen once, any idea what should i do?
Comment
Best Answer
Answer by Xarbrough · Apr 25, 2016 at 09:01 PM
bool isFirstTime = true;
void OnTriggerEnter2D(Collider2D other)
{
if(isFirstTime)
{
isFirstTime = false;
// do something here.
Debug.Log("Happens only once.");
}
}
Worked perfectly, as I expected, a simple use of a bool. I'm feeling so newbie !