I have a few GameObjects that implement a common Interface: IsTree. I need to call the function doTreeThing() on each of those IsTrees after getting a reference to each of them via FindGameObjectsWithTag("tree").
This line complains that it cannot implicitly convert from GameObject[] to IsTree[]
IsTree[] trees = GameObject.FindGameObjectsWithTag("tree");
So then I tried to leave the GameObject[] an iterate over it to convert each individual object inside to an IsTree.
GameObject[] trees = GameObject.FindGameObjectsWithTag("tree");
foreach (GameObject tree in trees) {
IsTree isTree = (IsTree)tree;
isTree.doTreeThing();
}
But this complains that it also cannot convert GameObject to IsTree.
Then I got a little desperate and tried to make my IsTree into a GameObject.
public class IsTree : GameObject {
public System.DateTime getAge(){
return null;
}
}
GameObject is a sealed type. (I don't really know what that means besides that this does not work)
So how do I get this array of GameObjects into an array of SomeInterface?