Instantiate objects in for loop
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public GameObject[] game;
public float ge;
bool asa;
// Use this for initialization
void Start () {
asa = true;
for (int i = 0; i < 5; i++) {
if (asa) {
Instantiate (game [i], transform.position, transform.rotation);
asa = false;
ge = 0;
}
}
}
// Update is called once per frame
void Update () {
if (ge >= 3f) {
Start ();
asa = true;
}
ge += Time.deltaTime;
}
}
whenever I do for loops the game[1] is instantiated
I want to instantiate
game[1]; game[2]; game[3]; game[4]; game[5];
for every 3 seconds
Comment
You shouldn't be calling the Start function from update, it is self-invoking. Use a different function name and call that from the Start/Update functions.
Your answer
![](https://koobas.hobune.stream/wayback/20220612095702im_/https://answers.unity.com/themes/thub/images/avi.jpg)