OnTriggerEnter - if other is of type, invoke method

I want to see if the object we are colliding with is of a certain type and then invoke a member function specific to that type’s class.

I can easily check to see if the other object is the type I want with a simple name or tag comparison, but then the method I want to call obviously can’t be called because Collider doesn’t contain a definition for it.

Example code of issue, where Disable is a method in the Block class:

void OnTriggerEnter (Collider other)
	if(other.tag == "Block")

What’s the best way get around this?

All monobehaviours have properties linking to their GameObject.
so if you wanted to disable other, you could do


You can also just do


Better to do a null check first.

MyScript myScript = other.GetComponent<MyScript>();
    // Do something awesome

Note: You are also abusing the word type. The type of every GameObject is GameObject. What you are asking to do is check if the GameObject has a specific component attached.