Hi I have a problem with my OnCollision code which freezes the game engine when three of the same game objects collide. The code is designed to instantiate a new game object when two of the same game objects collide. It works great for this but when three of the same objects collides it freezes. I am stuck on how to resolve this. Can anyone help me with this? Thank you.
void OnCollisionEnter2D(Collision2D other)
{
if (firstCollision == false)
{
UltraPumpkin sameCollide1 = other.collider.GetComponent<UltraPumpkin>();
if (sameCollide1 != null)
{
firstCollision=true;
other.gameObject.GetComponent<UltraPumpkin>().firstCollision = true; // prevent the other object from being able to do stuff
Destroy(other.gameObject);
MainEngine.instance.SameCollision(+16);
Instantiate(nextPumpkin, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
}