Hey I’m confused, how do I use GameObject.GetComponentsInChildren?
It returns a Component[ ] right?
But I’m trying to do what’s on the docs:
var hingeJoints : HingeJoint[];
hingeJoints = gameObject.GetComponentsInChildren(HingeJoint);
for (var joint : HingeJoint in hingeJoints) {
joint.useSpring = false;
}
But the problem is that hingeJoints : HingeJoint[ ] is an array of HingeJoint, not an array of Component, and that’s giving me errors…
when I compile I get this:
And when I ran the game I get this:
What’s the correct usage?
Btw, this is the code I’m using:
#pragma strict
var guiObject : GameObject;
function Start () {
}
function Update () {
var clickingButton : boolean = false;
if(guiObject != null){
var buttonList : GUITexture[] = guiObject.GetComponentsInChildren(GUITexture);
for(var i = 0; i < buttonList.Length; i++){
if (buttonList[i].HitTest(Input.mousePosition)){
clickingButton = true;
}
}
}
if(!clickingButton (Input.GetMouseButton(0) || Input.GetMouseButton(1))){
transform.RotateAround(Vector3.zero, Vector3.up, Input.GetAxis("Mouse X") * 5.0);
transform.position.y -= Input.GetAxis("Mouse Y") * 0.2;
transform.position.y = Mathf.Clamp(transform.position.y, 0 , 4);
transform.LookAt(Vector3(0,1,0));
}
}