Player collision activates GO

I’m currently working on a game that selects premade rooms for each time the level is loaded, so the layout is “random”. The only problem is, the game lags up and freezes upon the start. I am trying to make a script that toggles the spawning game object when the player collides with another object, but I don’t know the correct way to make the script toggle a gameobject. Does anyone know the answer to this?

There is much simpler logic than this.
Why not make an array of the different spawning objects (prefabs) and spawn them with a random index?

That’s very simple actually.

var spawnObject : GameObject[];
private var randomIndex : int;

function OnCollisionEnter (col : Collision)
{
 randomIndex = Random.Range (0,9);   //assuming you have 10 different spawning objects
 Instantiate(spawnObject[randomIndex], transform.position, transform.rotation);
 Destroy(col.gameObject);   //destroy the collision object
}

Otherwise if you wish to toggle a gameobject (for example a script) you need to use GetComponent() method.
Links >>>

Hope this helps. Btw, I haven’t checked the code if it works.