Game Development Reference
In-Depth Information
09 // Use this for initialization
10 void Start ()
11 {
12 }
13
14 // Update is called once per frame
15 void Update ()
16 {
17 }
18 }
In code sample 1-4, line 07 declares a completely empty array of GameObjects , named
MyObjects . To create this, it uses the [] syntax after the data type GameObject to
designate an array, that is, to signify that a list of GameObjects is being declared as
opposed to a single GameObject . Here, the declared array will be a list of all objects
in the scene. It begins empty, but you can use the Object Inspector in the Unity Editor
to build the array manually by setting its maximum capacity and populating it with
any objects you need. To do this, select the object to which the script is attached in
the scene and type in a Size value for the My Objects field to specify the capacity of
the array. This should be the total number of objects you want to hold. Then, simply
drag-and-drop objects individually from the scene hierarchy panel into the array
slots in the Object Inspector to populate the list with items, as shown here:
Building arrays from the Unity Object Inspector
 
Search WWH ::




Custom Search