Hello,
I have a bunch of components attached to an object. Each component has different properties, BUT each component has an enabled property I can set to true or false. What happens if I want to write a script that disables all the components on a certain object since ALL components contain the enabled property? Using…
var obj : GameObject;
obj.GetComponents(no arguments); //Generic version
GetComponents with no arguments is a generic function, which SEEMS to mean to me that the Type of ‘obj’ will fulfill the determination of whatever the return type ‘T[ ]’ of the GetComponents() function will be, so in THIS case, it would return an array of components inside obj that are of System.Type ‘GameObject’ since obj is of Type GameObject.
The problem is since I want to access EVERY component no matter what Type it might be, in order to access the ‘enabled’ property that EVERY component has, how would I be able to do that? What if Unity developed a function called doesPropertyExist(name : String) : boolean and could provide a way to code something like…
//If the property 'enabled' exists in the name component
if (GetComponent("name").doesPropertyExist("enabled")) {
//If the property 'enabled' is a boolean just like all the other 'enabled' properties in all other components.
if (GetComponent("name").doesPropertyExist("enabled").GetType() == boolean) {
//Disable the component.
GetComponent("name").enabled = false;
}
}
The OTHER problem would be storing multiple components with multiple types into a single array in order to access and change all the components of an object that have the same property name with the same type. How would I do this?
Thank you,
Michael S. Lowe