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:
function ApplyChanges()
{
renLoc1 = objLocations[iLocation].GetComponentsInChildren(Renderer); //Line 98
litLoc1 = objLights[iLocation].GetComponentsInChildren(Light);
for(var p=0;p<renLoc1.length;p++)
renLoc1[p].enabled = true;
for(var p2=0;p2<litLoc1.length;p2++)
litLoc1[p2].enabled = true;
}
The objects are declared above as such:
var objLocations : GameObject[];
var objLights : GameObject[];
private var renLoc1 : Renderer[];
private var litLoc1 : Light[];
private var iLocation : int;
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?