Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

For loop with instantiate crashing unity

$
0
0
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? :D 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; } } }

Viewing all articles
Browse latest Browse all 2383

Trending Articles



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