Game Development Reference
In-Depth Information
In this Unity document page, if we scroll down a litle bit, we will see the following
screenshot, which gives us our answer:
You will see that there are two types of GetComponentsInChildren() funcion. So, refer
to the following URL for more details:
http://unity3d.com/support/documentation/ScriptReference/GameObject.
GetComponentsInChildren.ltTgt.html .
If we go to the preceding link, we will see the following funcion:
function GetComponentsInChildren.<T> () : T[]
We can see that the preceding funcion takes the type T and returns an array of type T ,
which we will use in this step.
In our script, we cannot use the GetComponentsInChildren.<T>()
funcion, if we don't specify the type of our parameter as follows:
var waypointGizmos = gameObject.GetComponentsInChildre
n(Transform); //Correct
However, we will see the following error if we specify the type of our parameter:
var waypointGizmos : Transform[] = gameObject.GetCompo
nentsInChildren(Transform); //Error
The preceding code will cause the error in Unity shown in the following
screenshot:
It is beter to specify the type of the parameter based on its performance.
 
Search WWH ::




Custom Search