Reputation: 253
I have a problem finding all GameObjects in the scene containing scripts, which are derived from an abstract class.
Situation looks like this:
public abstract class IAbstractInterface: MonoBehaviour
{
}
public class Item_I_Need_To_Find1 : IAbstractInterface
{
}
public class Item_I_Need_To_Find2 : IAbstractInterface
{
}
....
How can I find all gameobject in the scene containing Item_I_Need_To_Find(%number%)
scripts?
I would really appreciate any help.
Thanks in advance.
Upvotes: 0
Views: 641
Reputation: 1580
The "is" operator is your friend.
if (myobject is IAbstractInterface)
{
...
}
Upvotes: -1
Reputation: 253
Well, I found solution on unity answers.
UnityEngine.Object.FindObjectsOfType< IAbstractInterface >();
worked like a charm!
Upvotes: 2