Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Problem with random spawning and coroutine

$
0
0
Hello everyone. I'm actually pretty a newbie at coding, and I'm trying to figure out how to spawn a prefab randomly picked every x seconds (i've made a public float, so I can test the timing directly from inspector) - anyway, with the code i've written, the spawning begins after x seconds, and then starts to spawn prefabs every frame. here's my code: using UnityEngine; using System.Collections; public class Game_manager : MonoBehaviour { public Transform[] teleport; public GameObject[] prefeb; public float waitTime; IEnumerator SpawnPics() { yield WaitForSeconds(waitTime); int tele_num = Random.Range(0,2); int prefeb_num = Random.Range(0,3); Instantiate(prefeb[prefeb_num], teleport[tele_num].position, teleport[tele_num].rotation ); } void Update(){ StartCoroutine("SpawnPics"); } } Can you help me figuring out where i'm going wrong? thank you :)

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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