I'm trying to write a script that cycles between showing different objects on screen, activating the current object, and deactivating the others.
I'm using GameObject.GetComponentsInChildren() to do this, and it's giving the following error:
InvalidCastException: Cannot cast from source type to destination type. LocationCustomization.ApplyChanges()(at Assets/MyAssets/Script/LocationCustomization.js:98)
Here is the ApplyChanges function in question:
The objects are declared above as such:
The thing that's really confusing me is that I even tried copy/pasting the GetComponentsInChildren() code from the official documentation, replacing the component being called with what I'm trying to use, and it still gave the same error.
Anyone see anything that I'm not?
asked Dec 30 '10 at 04:35 PM
The issue is that GetComponentsInChildren(type) returns Component, not YourType
What you can do is use GetComponentsInChildren.() instead
answered Dec 30 '10 at 04:37 PM