- Home /
Question by
user-4179 (google) · Aug 17, 2010 at 03:01 AM ·
arraystringsprint
Array of strings
How come this code generates a "cannot cast from source type to destination type" error on the line that prints?
var aircraftObjects = [ "Fuselage", "Left Alier", "Left Eleva", "Left Horiz", "Left Wing", "Right Alie", "Right Elev", "Right Hori", "Right Wing", "Rudder", "Vertical S" ];
for (var i in aircraftObjects) { print(aircraftObjects[i]); }
Comment
Best Answer
Answer by Jessy · Aug 17, 2010 at 03:53 AM
That's not how you use a for - in. loop. This is.
for (aircraftObject in aircraftObjects) print(aircraftObject);
Or, if you want to be really clear about things,
for (var aircraftObject : String in aircraftObjects) Debug.Log(aircraftObject);
Why Unity doesn't warn you about this, I don't know.