I’m trying to use for loop as you can see in the code below, unity is crashing every time when i try to build this. Can anybody explain me why its crashing?
I want this loop to be infinite.
GameObjects are set in Unity Editor.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapManager : MonoBehaviour {
public GameObject mainObject;
[Header("Map elements")]
public GameObject[] elements;
private int index;
private float timer;
private float timeLimit;
void Start () {
}
void FixedUpdate () {
timer += Time.fixedDeltaTime;
Debug.Log("Timer: " + timer);
if (timer >= 2f)
{
for (int i = 1; i >= 0; i++)
{
index = Random.Range(0, elements.Length);
Instantiate(elements[index], new Vector3(0, 20 * i, 0), Quaternion.identity, mainObject.transform);
}
timer = 0;
}
}
}