- Home /
How to make my game objects spawn when i walk through collider
Hi Guys. I'm Creating a Zombie game. (Not Relevent) How do i make them appear only when i walk through the second rooms collider. Is there a script reference or tutorial on how to do this?
eg. Kill all enemys in first room. When i walk through the collider more enemys will spawn. Can i hide enemys by deactivating childeren and how would i reactivate on colider enter. Any info is appreciated thanks.
Answer by Dreamora · Jul 02, 2012 at 06:53 PM
All you need to do is use the OnCollisionEnter function and implement your Instantiate(SomePrefab) function where SomePrefab is a public variable defined on the class (C#) or just outside of functions (UnityScript) which you assign the target game object to within the editor.
you can use this script on all your spawn colliders and every time assign a completely different game object if you want
Answer by eeveelution8 · Mar 02, 2014 at 02:05 AM
var items : GameObject [];
function OnTriggerEnter()
{
collider.enabled = false;
var index : int = Random.Range(1,items.length);
var thePrefab : GameObject = items[index];
var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613073603im_/https://answers.unity.com/themes/thub/images/avi.jpg)