Hi guys, so currently in my script Im just trying to get every gameobject within an array to do something (not yet determined, so dont worry about the commented out bit), but my for statement is returning an error, only at runtime-
InvalidCastException: Cannot cast from source type to destination type.
heres the code
function Start () {
var MyArray = new Array(GameObject.FindGameObjectsWithTag("Bad"));
var MyIndex = Random.Range(0, MyArray.length);
Debug.Log(MyArray[MyIndex]);
Debug.Log(MyArray[2]);
var MyArrayStorage = new Array (GameObject);
MyArrayStorage.Add(MyArray[MyIndex]);
Debug.Log (MyArrayStorage);
for(var item : GameObject in MyArrayStorage){
// item.SetActive (false);
}
}
No doubt someone will also complain about my use of JS array, and so if you can suggest a better way to do this kind of array, that’d be a great bonus, but obviously the main issue is the error
thanks guys