I can’t loop through transforms in JS (pragma strict) without getting a warning, if I type the variable. It seems wrong.
Bug?
Example:
for(var child:Transform in transform)
{
//gives WARNING: Implicit downcast from 'Object' to 'UnityEngine.Transform'.
}
//i have to do this to get rid of warning:
for(child in transform)//no type define, no warning!!
{
var ct:Transform = child as Transform;//get typed
}
My guess is that it occurs because Transform is an IEnumerable rather than IEnumerable.
More info (tested);
//Works fine in C#
foreach (Transform child in transform)
{
print(child.gameObject.name);
}
/*Fails because it casts child as object.
foreach (var child in transform)
{
print(child.gameObject.name);
}*/
//Also works fine because compiler has sufficient info
//Uses System.Linq
foreach (var child in transform.Cast<Transform>())
{
print(child.gameObject.name);
}