I am being trying to create a space shooter game for a while now, right now i trying to create a enemy spawn script from a video i see on youtube, now this script keep loop or restarting for first after i kill the last boss now i want it to stop and trigger finish game UI so my player can go to the next level but the script keep respawn waves of enemy over and over the person i learn from is brackey and he said in the video if i want to have a finish screen of stop the relooping i have to do it right where
if (nextWave + 1 > waves.Length - 1)
{
nextWave = 0;
Debug.Log("ALL WAVES COMPLETE! Looping...");
}
but i try disable nextWave =0; and it not working it keep spawn waves one only
and not i try disable
else
{
nextWave++;
Debug.Log ("Starting next waves");
}
nextWave++; it keep looping last boss only i just don't know what to do here the entire script
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public Wave[] waves;
public GameObject Enemy;
public Transform[] Spawn;
Wave currentWave;
int currentWaveNumber;
int enemiesRemainingToSpawn;
int enemiesRemainingAlive;
float nextSpawnTime;
void Start () {
NextWave ();
}
// Update is called once per frame
void Update () {
if (enemiesRemainingToSpawn > 0 && Time.time > nextSpawnTime)
{
enemiesRemainingToSpawn--;
nextSpawnTime = Time.time + currentWave.timeBetweenSpawns;
int SpawnIndex = Random.Range (0, Spawn.Length);
GameObject spawnedEnemy = Instantiate (Enemy, Spawn[SpawnIndex].transform.position, Quaternion.identity) as GameObject;
spawnedEnemy.GetComponent().OnDeath += OnEnemyDeath;
}
}
void OnEnemyDeath ()
{
enemiesRemainingAlive--;
if (enemiesRemainingAlive == 0) {
NextWave ();
}
}
void NextWave () {
currentWaveNumber++;
if (currentWaveNumber - 1 < waves.Length) {
currentWave = waves [currentWaveNumber - 1];
enemiesRemainingToSpawn = currentWave.enemyCount;
enemiesRemainingAlive = enemiesRemainingToSpawn;
}
}
[System.Serializable]
public class Wave {
public Transform enemy;
public int enemyCount;
public float timeBetweenSpawns;
}
}
↧