Compare scripts with collider. Please help!

Sorry I don’t have a specific example or if this is simple but I basically have colliders (like cannon balls) that fly at each other. When the collision happens the health of each is compared, if ball one has 120 health and the ball two has 90, i want ball two to be destroyed (this part I can do) and ball one to continue flying in direction specified with 30 health.

So all that being said, how do I make sure that when a collision2D happens that the objects can check the colliders health (part I can’t figure out) as well as each of them subtract their health’s from the other.

Just compare the health on each projectile and have logic to decide what to do with that value;

    public void OnCollisionEnter2D(Collision2D collision)
    {
        //Check we have collided with another cannonball
        var otherBall = collision.transform.GetComponent<MyProjectileScript>();
        //If we haven't exit the method
        if (otherBall == null)
            return;
        //We have collided with another cannonball so we get its current health
        var otherHealth = otherBall.health;
        //If it has more health than us, Destory ourselve and exit the method
        if (otherHealth > health)
        {
            Destroy(gameObject);
            return;
        }
        //This ball had more health than other so its health gets reduced by the amount of health the other had
        health -= otherBall.health;
    }

This line: var otherBall = collision.transform.GetComponent();

Literally been looking for HOURS and couldn’t find something like this. THANK YOU SOOOOO MUCH!