Most effective way to get the methods of any collider object in Unity?

Most effective way to get the methods of any collider object in Unity?

I have a bullet game object that detects enemies via&nbsp;<code>OnTriggerEnter2D()</code>. This was working perfectly until I added different enemy types:

I have a bullet game object that detects enemies via OnTriggerEnter2D(). This was working perfectly until I added different enemy types:

private void OnTriggerEnter2D(Collider2D collision)
    {
        Enemy enemy = collision.GetComponent<Enemy>();
        if (enemy != null)
        {
            enemy.Destroy();
            GameObject effect_ = Instantiate(bulletEffect, transform.position, transform.rotation);
            Destroy(effect_, 0.5f);
            Destroy(gameObject);
        }

}

So simply if the bullet collides with Enemy() then it should call its Destroy() method.

The problem is that now I have added multiple enemies in my game, for example there is an enemy with the class name Runner() with its own death method.

I can add an if condition and cycle through every enemy type but that will become tedious after more enemies are added.

Whats the best way of doing this?

Thanks

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

some issues with a c# jumping code in unity

This the code I am having issues with, in fact when I press the space button, the player will just repeat the animation of jump and even the right arrow doesn't work anymore.