- Home /
gameObject[] Length
How can i set the length of a gameObject[] in the Start function???
Answer by AlucardJay · Mar 11, 2013 at 01:54 AM
Here is an excellent link that you should keep permanently bookmarked !
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?
The type of array you are suggesting here is a Built In array, so scroll down to (Im assuming uJS here) :
var myNumbers = new int[10]; // declaration example using ints
Quick tip : only use a Built In array for something that is going to be of fixed size , meaning the length of the Built In array is never going to change.
For an array that you add too and take away from, use Generic List, keep scrolling down that page and all the notes on how to use it are there. Here is a checksheet I made from this page (again in uJS) :
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?
My list notes :
// to use List
import System.Collections.Generic;
// declare
var inRangeList : List.< GameObject > = new List.< GameObject >();
var inRangeList : List.< GameObject >;
inRangeList = new List.< GameObject >();
// Add object to list :
inRangeList.Add( theItem );
// length
inRangeList.Count;
// from position
inRangeList[ index ];
// empty list
inRangeList.Clear();
// send to builtin array
inRangeList.ToArray();
Thank you very much :) I really love it when someone can give me a really detailed and useful answer!