I am not very good at coding and I need a script to spawn 10-15 enemies at once when I enter a collider trigger.
Thanks in advance!
I am not very good at coding and I need a script to spawn 10-15 enemies at once when I enter a collider trigger.
Thanks in advance!
Thanks, I will be reading this but for now I need a reference script on how to spawn enemies when you enter and exit a collider. Thanks though.
Look in the doc for the examples on OnTriggerEnter() and OnTriggerExit(). Once you have the examples working, post your code here to get further help. If you have your script working with entering and exiting triggers, take a look at Instantiate in the Scripting References. Instantiate examples will show you how to spawn prefabs into the scene.
Simple for you can reference.
//private
private bool isSpaw = false;
private GameObject _Enemy;
//public
public GameObject _PrefabEnemy;
void OnTriggerEnter(Collider other)
{
if(!isSpaw)
{
for(int i = 0; i< 5; i++)
{
_Enemy = Instantiate(_PrefabEnemy, other.gameObject.transform.position + new Vector3(Random.Range(0,10),0f,Random.Range(0,10)), Quaternion.identity) as GameObject;
}
isSpaw = false;
}
void OnTriggerExit()
{
Destroy(GameObject.Find("_Enemy(Clone)");
}