Mad
Mad

Reputation: 253

Find all GameObjects in the scene containing scripts, which are derived from an abstract class

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

Answers (2)

Udontknow
Udontknow

Reputation: 1580

The "is" operator is your friend.

if (myobject is IAbstractInterface)
{
   ...
}

Upvotes: -1

Mad
Mad

Reputation: 253

Well, I found solution on unity answers.

UnityEngine.Object.FindObjectsOfType< IAbstractInterface >(); worked like a charm!

Upvotes: 2

Related Questions