Question by
importguru88 · Aug 20, 2016 at 05:32 PM ·
spawnhowspawnpointsspawner
How do I spawn a certain amount of enemy ai / It's spawning too many enemy ai's in my scene
I want spawn for or five enemy ai. I have the enemy ai's spawning in the update function because it was didn't work well in a spawn function I had created only one spawnpoint work . I have two in my scene . I need to slow down the spawning and spawn certain amount in my scene . Here is my code :
using UnityEngine;
using System.Collections;
public class EnemiesSpawner : MonoBehaviour {
public GameObject enemy;
public Transform [] spawnPoints;
public float spawnTime = 20f;
public Vector3 spawnValues;
void Start () {
InvokeRepeating("Spawn", spawnTime, spawnTime); //Calls the "Spawn" function every 10 seconds.
}
void Update () {
int spawnPointIndex = Random.Range (0, spawnPoints.Length); for( int spawnCount = spawnPoints.Length - 1 ; spawnCount >= 0 ; --spawnCount )
Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 1, Random.Range (-spawnValues.z, -spawnValues.z) ) ; // <= here
}
}
Comment
Your answer

Follow this Question
Related Questions
[C#] Only one instantiate object is working, the rest is not.. Help meee 0 Answers
uNet Spawning Objects 0 Answers
How i can spawn enemies of different types??? 0 Answers
How to know if there is no possible space on board to spawn. 1 Answer
how can I add a maximum of enemies to be generated for each wave? 0 Answers