So I created this script recently to spawn a "enemyPrefab" every x seconds. But when the function is called on my Unity client just crashes and I have to open up Task Manager and manually End Task it for it to close.
Here's my script:
#pragma strict
//Variable list
public var spawner : Transform[];
public var spawnTime : float;
public var enemyPrefab : GameObject;
private var spawner_num : int;
function Start ()
{
//Call the SpawnEnemy function every spawnTime seconds
InvokeRepeating ("SpawnEnemy", spawnTime, spawnTime);
}
function SpawnEnemy ()
{
//Tells the log that the function has been called upon
Debug.Log("Started");
while (true)
{
//Picks a random spawner to spawn "enemyPrefab" out of
spawner_num = Random.Range(0,3);
//Tells log what spawner has been picked
Debug.Log("Spawner is spawner number " + spawner_num);
//Spawns the "enemyPrefab" at the spawner location
Instantiate(enemyPrefab, spawner[spawner_num].position, spawner[spawner_num].rotation );
}
//Tells the log the function has ended.
Debug.Log("Ended");
}
Thank you so much if you can help me out on this, I've been trying to advance my game for about 30 minutes now googling this topic but can't find the answer, but anything helps! :)
(P.S. I'm on Windows if that helps any.)
↧