- Home /
Problem with Application.Loadedlevel
Hello everyone. I've got a problem with the "retry" button on my GUI: it reloads the scene, but the spawner I have in it does not work, and I can't understand why. The code I use in Unity 4.6 Beta to load the same level is
function Reload () {
Application.LoadLevel(Application.loadedLevel);
}
and the code attached to my spawner is
var enemy : GameObject;
var spawnValues : Vector3;
var hazardCount : int;
var anglex : int;
var angley : int;
var anglez : int;
var spawnWait : float;
var startWait : float;
var waveWait : float;
var randomnumber : float;
public var isSpawning :boolean = true;
function Awake(){
if (!isSpawning) {
isSpawning=true;
}
}
function Start () {
if (isSpawning==true){
SpawnWaves ();
}
}
function SpawnWaves () {
yield WaitForSeconds (startWait);
while (true)
{
for ( var i : int= 0; i < hazardCount; i++)
{
var spawnPosition : Vector3= new Vector3 (Random.Range(-randomnumber,randomnumber), spawnValues.y, spawnValues.z);
var spawnRotation : Quaternion= Quaternion.Euler(anglex, angley, anglez);
Instantiate (enemy, spawnPosition, spawnRotation);
yield WaitForSeconds (spawnWait);
}
yield WaitForSeconds (waveWait);
}
}
Any help would be very appreciated.
Thank you! :D
Im not too sure, but possibly after loading the scene, you could access the script and do script.enabled = false; and then instantly do script.enabled = true; This should refresh the script, as you have code that executes on Awake(), which is started when the script is started. This may not be the problem but hope it helps.
Awake shouldn't be the problem because 'isSpawning' is being initially set to true. But if it is, may be you should cut n paste it from Awake to Start to give it a little bit more time?