Quantcast
Channel: Questions in topic: "invokerepeating"
Viewing all articles
Browse latest Browse all 220

My script keeps crashing my Unity Editor Client. Please help

$
0
0
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.)

Viewing all articles
Browse latest Browse all 220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>