Game frozen with multiple prefabs instatiated.
I am new to Unity c# and coding in general. My game has multiple Rigidbody2D prefabs with circle collider2D of varying sizes. When 2 Gameobjects of same size & tag ( clones of same prefab) collide I want to destroy them both and instantiate a new gameobject of bigger size (another prefab) I use this code to do that.
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Sphere1")
{
Destroy(collision.gameObject);
if (GetInstanceID() < collision.gameObject.GetInstanceID())
{ Instantiate(Sphere2, transform.position, transform.rotation); }
}
}
I
During the game when multiple collisions are happening large prefabs are instatiating spontaneously and the game screen getting stuck. please Help
Comment