How to instantiate multiple prefabs using OnCollisonEnter (C#)

I have an “egg sack” that currently gets destroyed when it collides with the ground. I want this collision to also instantiate “BabySpiders”, which I have saved as a prefab. These “BabySpiders” have a collider and a rigid body. I want these spiders to spawn in the same location that the egg sack gets destroyed. Thank you so much ahead of time! =) Currently I have this code:

void OnCollisionEnter2D(Collision2D col)
if ( == “Platform”)


Before it destroy itself, instantiate the BabySpiders at the egg sack’s location.

public GameObject babySpiders; // Drag the prefab here.

Instantiate(babySpiders, transform.position, /*Set your own rotation*/);

You can put that in a for loop to create multiple Baby Spiders or you can set the parameters yourself.

//in the editor assign the prefab to this.
public GameObject BabySpider;
int spawncount = 4;
GameObject Temp;

void OnCollisionEnter2D(Collision2D col) { if ( == "Platform") {
for(int X = 0; X <= spawncount; X++){
    Temp = instantiate(BabySpider) as GameObject;
    Temp.transform.position = col.transform.position + (X * col.transform.forward);



now you should have a line of 4 spiders.