I am doing a simple for loop in the start function. I added #pragma strict for optimisation reasons and now I am getting the error: BCE0019: ‘gameObject’ is not a member of ‘Object’.
#pragma strict
import System.Collections.Generic;
import System.Linq;
var allProjectiles = new List.<GameObject>();
function Start () {
//Add every immediate child only of the transform to the list above as a gameobject
for (var child in transform){
allProjectiles.Add(child.gameObject);
}
}
If I cast the child as a gameobject in this way:
for (var child: GameObject in transform){
I get an invalid casting error instead: InvalidCastException: Cannot cast from source type to destination type.
What is the correct way to do this? I’m not getting errors in any of my other for loops, and the only similar solutions I can find on UA are for getcomponent not for loops.