- Home /
After player has died reset scripts
When the player has died and has went back to the main menu and clicked start game none of my scripts seem to be working mainly my spawning script Example:
var AISpawn : Transform[];
var allEnemies : GameObject[];
static var currentEnemies : int = 0;
var maxEnemies : int = 1;
var minEnemies : int = 0;
var spawn = false;
var spawnTime : float;
static var enemiesDead : int;
var enemies : int;
var round : int = 0;
var roundText : GUIText;
var increaseRound : boolean = false;
function Start()
{
while (true)
{
if(currentEnemies <= 0)
{
currentEnemies = 0;
spawnTime -= 0.1f;
AI.speed += 2.0;
ShipRotate.rotateSpeed -=0.1;
increaseRound = true;
maxEnemies += 1;
}
if (currentEnemies <= minEnemies)
spawn = true; // if minEnemies reached start spawning
if (currentEnemies >= maxEnemies)
spawn = false; // if maxEnemies reached stop spawning
if (spawn){ // if spawning enabled create new enemy
// Randomize the different enemies to instantiate.
var obj : GameObject = allEnemies[Random.Range(0, allEnemies.length)];
// Randomize the spawnPoints to instantiate enemy at next.
var pos: Transform = AISpawn[Random.Range(0, AISpawn.length)];
Instantiate(obj, pos.position, pos.rotation);
currentEnemies +=1;
}
yield WaitForSeconds(spawnTime); // free Unity for 2 seconds each loop anyway
}
}
function Update()
{
roundText.text = round + "";
enemies = currentEnemies;
if(increaseRound == true)
{
round++;
increaseRound = false;
}
if(spawnTime <= 0.9)
{
spawnTime = 0.9;
}
if(increaseRound == true)
{
round++;
increaseRound = false;
}
if(maxEnemies >= 18)
{
maxEnemies = 18;
}
}
Comment
Have you tried deactivating the gameobjects and reactivating them?
Do you mean when the player dies Deactivate them then when you press the start button activate them?
Yes, I did, but now that I think of it you might want to look into reloading the scene when you hit start. http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html