- Home /
Error in for loop
I have this for loop:
for (var i in jsMonsters) {
Debug.Log(jsMonsters[i]);
}
Which gives me this error message:
InvalidCastException: Cannot cast from source type to destination type.
Can you explain why that is happening?
Thanks - Elliot Bonneville
Also, so I don't have to edit my Question with more information later, here's what populates the array:
function ReadFile () { var sr = new StreamReader(Application.dataPath + "/" + readFilePath); var fileContents = sr.ReadToEnd(); sr.Close();
var monsters : String[] = fileContents.Split("-"[0]);
var jsMonsters = new Array(monsters);
}
We can close this. Vote to close as spam if you see it.
Answer by Mike 3 · Jul 29, 2010 at 08:42 PM
It should just be Debug.Log(i);
It's already the string you're interested in
Your answer

Follow this Question
Related Questions
Find objects with tag? 1 Answer
"For"-Loop only works for final element in array 1 Answer
How to deactivate all GameObject in a array, except last one 4 Answers
Array or for loop doesn't work with state machine in Unity, gives NullReferenceException 1 Answer
C# For loop in button to set gameObjects in array to active 1 Answer