Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How to make my enemies spawn at spawn point, but not randomly?

$
0
0
I want my enemies to spawn at my spawn points but not randomly. For example, I have 5 spawn points and I want to instantiate one enemy on each spawn point. Here is my EnemySpawner script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemySpawner : MonoBehaviour { public GameObject[] spawners; public GameObject enemy; float waveCountdown; public float timeBetweenWaves = 5f; int waveNumber = 0; public int enemySpawnAmount = 0; public int enemiesKilled = 0; void Start() { waveCountdown += Time.deltaTime; spawners = new GameObject[5]; for (int i = 0; i < spawners.Length; i++) { spawners[i] = transform.GetChild(i).gameObject; } StartWave(); } void Update() { if (waveCountdown > timeBetweenWaves) { SpawnEnemy(); } if (enemiesKilled >= enemySpawnAmount) { NextWave(); } } void SpawnEnemy() { int spawnerID = Random.Range(0, spawners.Length); Instantiate(enemy, spawners[spawnerID].transform.position, spawners[spawnerID].transform.rotation); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles