First off my whole script is here to avoid questions, most of it isnt needed here. In the start round function I increase maxZombies by 5. However in the NightTime function it acts as if maxZombies IS 5 and only allows 5 enemies to spawn. Even though during the game in the inspector I can see that maxZombies is not 5, it was in fact increased by 5. So basically the scipt is acting as if maxZombies is whatever I set enemyDifficulty.numberAdd to. Any ideas?
var round : int = 1;
var roundInProgress : boolean = true;
var enemyDifficulty : EnemyDifficulty;
var zombie : GameObject; //Set the zombie model in the inspector
var maxZombies : int; //set max zombies in this round
var maxLiveZombies : int; //set max zombies alive at once
var zombiesThisRound : int = 0; //this is the number of zombies that have spawned this round, alive or dead
private var previousSpawnPoint : GameObject; //this is where the last zombie spawned
class EnemyDifficulty
{
var healthMulti : float = 1.05;
var speedMulti : float = 1.02;
var numberAdd : int = 5;
}
@HideInInspector
var enemys : GameObject[];
var remainingEnemys : int;
var remainingAliveEnemys : int;
var NoSpawnPoints : int;
var lightOn : boolean = false;
var bigLight : GameObject;
var smallLight : GameObject;
function Start ()
{
previousSpawnPoint = GameObject.FindGameObjectsWithTag("spawnpoints")[0]; //this will break if you have no spawnpoints tagged "spawnpoints".
NoSpawnPoints = GameObject.FindGameObjectsWithTag("spawnpoints").Length;
}
function Update ()
{
if (!roundInProgress)
DayTime();
else
NightTime();
}
function StartRound ()
{
//////DIFFICULTY
maxZombies += enemyDifficulty.numberAdd;
round++;
roundInProgress = true;
}
function DayTime ()
{
if (!lightOn)
{
bigLight.animation.Play("LightFadeIn");
smallLight.animation.Play("LightFadeOut");
lightOn = true;
}
if (Input.GetButtonDown("Action"))
StartRound();
}
function NightTime ()
{
////////// SPAWN ENEMIES && END ROUND ONCE KILLED //////////
enemys = GameObject.FindGameObjectsWithTag("Enemy");
remainingEnemys = maxZombies - zombiesThisRound;
remainingAliveEnemys = enemys.length;
if (lightOn)
{
bigLight.animation.Play("LightFadeOut");
smallLight.animation.Play("LightFadeIn");
lightOn = false;
}
if (GameObject.FindGameObjectsWithTag("Enemy").length < maxLiveZombies && zombiesThisRound < maxZombies && roundInProgress) //while zombies need to spawn because there aren't enough on the map and enough zombies haven't spawned yet.
{
var spawnPoints = GameObject.FindGameObjectsWithTag("spawnpoints"); //get a list of all spawn points
var spawnPoint = previousSpawnPoint; //choose a default spawn point
if(spawnPoint == previousSpawnPoint && spawnPoints.length > 1) //keep choosing a random spawn point until you choose one you haven't choosen yet
{
spawnPoint = spawnPoints[Mathf.Floor(Random.Range(0,spawnPoints.length))];
}
previousSpawnPoint = spawnPoint; //store where the zombie spawn last
Instantiate(zombie, spawnPoint.transform.position, spawnPoint.transform.rotation); //create the new zombie
zombiesThisRound++; //increase the number of spawned zombies.
}
if (zombiesThisRound == maxZombies && remainingAliveEnemys == 0)
roundInProgress = false;
/////////////////////////////////
}