Hey,
Simple question: how are you supposed to loop through a game object’s children with #pragma strict?
for (var child : Transform in transform)
is giving me “BCE0022: Cannot convert ‘Object’ to ‘UnityEngine.Transform’.”
Thanks.
Hey,
Simple question: how are you supposed to loop through a game object’s children with #pragma strict?
for (var child : Transform in transform)
is giving me “BCE0022: Cannot convert ‘Object’ to ‘UnityEngine.Transform’.”
Thanks.
Not sure if everything’s working as desired yet, but this code is at least not throwing errors:
var myVar : Component[] = gameObject.GetComponentsInChildren(GameObject) as Component[];
for (var child in cubesForRow) {}
edit: nevermind that solution, i don’t know what to do.
Add “#pragma downcast”.
–Eric
i would love to, but this is for iOS.
things have to work under #pragma strict for iOS, correct?
Yes, #pragma downcast is used in combination with #pragma strict. #pragma strict before Unity 3 included #pragma downcast and #pragma implicit (and worked fine with iOS).
–Eric
oh fantastic. thanks.
#pragma downcast will not solve the problem on the Android Platform.
You must cast the child’s type as the class that the function belongs too. Here’s an example that worked for me:
var allChilds: childClass[] = Parent.GetComponentsInChildren.<childClass>();
for(var i : int = 0; i < allChilds.length; i++){
if(allChilds[i].x == y){
allChilds[i].callFunction();
}
}
Hope this helps somebody! Worked for me. PM or Email with questions.