I have created several clases, say B,C,D… derived from a Monobehaviour class A. I use
GetComponent
to get all of them as it is easier, but… Is there any way to check if the component returned is of type class B, C etc…?
Sure:
//C#
A instance = GetComponent<A>();
if (instance is B)
{
// instance is of type B
}
or
//C#
A instance = GetComponent<A>();
B bInstance = A as B;
if (bInstance != null)
{
// instance is of type B
// do something with bInstance
}