Im looking for this trigger to only work once, the first time. I managed to transcript this and found some alternatives to add the function either by destroying the collider or limiting its function, but i lack the c# knowledge to add on it. If anyone knows, it would be every helpful!
You can limit it with a boolean variable:
private bool isFirstCall = true;
void OnTriggerEnter2D(Collider2D col)
{
if (isFirstCall)
{
isFirstCall = false;
// next, your logic
}
}
1 Like
Thanks! i found a way to destroy the collider on exit too
Destroying and Instantiating during Runtime is not a best Practice to use Unity due to performance issues. Instead of Destroying, you can disable the target component.
1 Like
Please mark this as resolved and makaka-org as the guy who resolved it please.
2 Likes
