Declaring collider types

I am using two similar functions on a character that distinguishes between a box collider and a sphere collider. I though by using -

void OnTriggerEnter(SphereCollider other)
    {
//Do stuff
}

void OnTriggerEnter(BoxCollider other)
    {
//Do different stuff
}

I would be able to call different actions, however I am getting the error -
Script error: OnTriggerEnter
This message parameter has to be of the type: Collider

I know that using the word Collider, would call the function. However that calls any type of Collider, not a specific collider, which is what I am trying to do. MonoDevelop didn’t have any problem with me typing SphereCollider and BoxCollider, even having it in the auto complete suggestions.

Maybe I am missing something under using Unity… using System… Could someone please advise me on how to look for Trigger colliders separately, i.e. one way for Boxes and another for Spheres?

void OnTriggerEnter(Collider other) {
if (other is BoxCollider) {
BoxCollider otherAsBox = other as BoxCollider;
}
else if (other is SphereCollider) {
}
}
1 Like

Thank you, it works as intended. Much appreciated.