run a code only once when two of the same gameobjects collide

The solution for “run a code only once when two of the same gameobjects collide” can be found here. The following code will assist you in solving the problem.

OnCollisionEnter2D(Collision2D other)
{
if(other.GetInstanceID() > GetInstanceID())
{
whatever you want to run
}
}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in