Handling OnTriggerEnter2D for different object types

Excuse me because this must’ve been asked before but I’ve searched for 30m already…

I have a Player object firing instantiated prefab Bullets. The Bullet prefab’s Collider2D is set to IsTrigger. The prefab has a “OnTriggerEnter2D” method in its script which, when detecting a collision with an enemy object, gets the enemy’s script component and sends it a message. Like this:

    private void OnTriggerEnter2D(Collider2D collision)
    {
        AsteroidController ast = collision.gameObject.GetComponent<AsteroidController>();

        if (ast != null)
        {
            ast.Break();
        }

        Destroy(gameObject);
    }

This works just fine. However, now I need to add more types of enemies which behave completely differently and don’t have the AsteroidController script attached to them. They have other scripts and other behaviors, and should react differently when hit.

I’d like to be able, when detecting a “TriggerEnter”, to send the same message to different object types (i.e. “You were hit”), and let the object decide what to do next.

I can do this by comparing tags and then, with a Switch statement, go through all possible enemy types and do the proper GetComponent on them to get to the script. But this seems very inelegant to me (although maybe it’s the only solution at my very-much-a-newbie level).
Isn’t there a simple way to call a method on whichever Collider2D object that you get from OnTriggerEnter2D? Do I have to check its type in the triggering object itself beforehand?

Thanks.

// on trigger enter code
private void OnTriggerEnter2D(Collider2D collision)
{
Enemy enemy = collision.gameObject.GetComponent();

     if (enemy != null)
     {
         enemy.DoSomethingWhenHit();
     }
 }
 // example class Enemy
 public class Enemy : MonoBehaviour
 {
     public float hp;
     public bool isDead;
     public virtual void DoSomethingWhenHit()
     {
         (...) // code for every enemy
     }
 }
 // example EnemyController
 public class EnemyController1 : Enemy
 {
     public override void DoSomethingWhenHit()
     {
         base.DoSomethingWhenHit();
         (...) // code for only this enemy
               // for example destroy object or just decrease hp
     }
 }

You need Inheritance. Where you define a base class called enemy which has a function onBulletHit(). You will provide the implementation of this function in all base classes as you want. Then you can simply get all the derived base classes as Enemy and call appropriate onBulletHit().