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 :)
↧