Question by
masturbator · Nov 06, 2016 at 02:03 AM ·
instantiateprefabonce
how do i instaniate prefab for once
void Start () {
StartCoroutine(waitSpawner());
}
void Update () {
spawnWait = Random.Range(spawnLessWait, spawnMostWait);
}
IEnumerator waitSpawner()
{
yield return new WaitForSeconds(startWait);
for (int i = 0; i < 1; i++)
{
while (!stop)
{
randDot = Random.Range(0, 1);
Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), Random.Range(-spawnValues.y, spawnValues.y), 1);
Instantiate(dots[randDot], spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
yield return new WaitForSeconds(spawnWait);
i tried everything but i couldnt find the solution yet. thanks a lot
Comment
If you want to instantiate a prefab only once, then why are you using for and while loop? Just instantiate the prefab outside of for loop.
Your answer
