the for statement in unity 3d for iphone

hello!

I want transfer a unity project to iphone platform.

After I deal with all the #pragma strict and Getcomponent issue ,I found runtime error still happen:

the error message: NullReferenceException: Object reference not set to an instance of an object

the statement:

var gos : Renderer[ ];
gos = GetComponentsInChildren(Renderer) as Renderer[ ];

var go : Renderer;
for( go in gos ) { ← this statement get error message!!!
go.enabled=false;

}

it seems the original use of “for” can not use in iphone platform,WHY???

the statement:

Debug.Log (“gos.length=”+gos.length);

also get the same error message.

thank you

You can’t cast an array of one type to an array of another type, so the as operator is returning null. Since you’re using a foreach loop, though, you can just specify the type and cast there:

for (go : Renderer in gos)