I started using #pragma strict and have the error cant convert object to transform, how would i loop through the children of a transform without errors strongly typed?
var thing:Transform;
Function Start(){
for(var child:Transform in thing){
//do stuff
}
}
1 Answer
1
I found using ‘as Transform’ like
var stuff:Transform=GetStuff() as Transform;
can settle most of the #pragma strict errors.
for looping through children though, what i found works is to:
var thingsChildList:Transform[]=thing.GetComponentsInChildren(Transform) as Transform[];
for(var child:Transform in thingsChildList){
//do stuff
}
the only error I see is that function should be a lower case 'f'. What errors are you getting?
– Peter_GWhile using #pragma strict i was getting Cannot convert 'Object' to 'UnityEngine.Transform', when i was going through a transforms children with a 'for in' loop, that kind of for loop seemed to return Objects, not transforms, when iterating through the children. I think that has to do with how a transform stores its children; as enumerations er something i think, that's where the documentation info i could find stopped.
– anon44971466I never implied you were stupid. I just tried to understand the system you're implementing because I didn't make sense for me (simply because I didn't have the whole context). But even with your explanation, I also share logicandchaos' point of view. I believe you're taking the wrong path.
– Hellium