I'm trying to access the children in a prefab. Internet says that I should use:
`var child = transform.Find("child");`
I got it to work once (that file is long gone), but since then it always returns a null. My current scene includes the following hierarchy:
vehRigA
-axleFront
-axleRear
But the following code,
var axleF = transform.Find("axleFront");
function update(){
print(axleF); // returns: null
}
shows that the Find() is not finding.
What am I doing wrong?
Should I be using GameObject.Find(),(tried it and got an error) or another kind of Find?
(why can't we access a child by "parent.child"? I thought that was the definition of OO programing?)
Okay, seems I'm learning a scripting syntax lesson: Spaces are important; you must put spaces everywhere or it does not work.
//does not work
var axleF:Transform;
function start(){
axleF = transform.Find("/vehRigA/axleFront");
}
function Update () {
print(axleF);
}
//works
var axleF : Transform;
function Start () {
axleF = transform.Find("/vehRigA/axleFront");
}
function Update(){
print(axleF);
}