Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How to instantiate everything inside an Array?

$
0
0
Hi, I have an array of gameobjects. Onstart I would like all of these objects in the array to be instantiated. Although this script is attached to several other items so the amount in the array is not specific. One will have 3 items to instantiate, the other will have 5 or maybe 6. The idea is to be able to drag prefabs into the inspector to set them to instantiate on load. Here is what I have so far, can anyone tell me what I am doing wrong? using UnityEngine; using System.Collections; public class MyDrops : MonoBehaviour { public GameObject[] Items; //Using on start to test. void Start () { DropItems(); } //First Attempt to instantiate all the items in the Items[] array. void DropItems() { Instantiate(Items[Items.Length] ,transform.position, Quaternion.identity); } //Second Attempt. (Error, value expected in "Items[ here ]".) //An Object reference is required for the non-static field, method, or property. public static void Drop(GameObject[] itemArr) { foreach (GameObject i in itemArr) { Instantiate(Items[], transform.position, Quaternion.identity); } } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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