How do I do TryGetComponentInParent?

I have a game object that references a script in the parent. The script can be one of three. I would like to not make a new object and script for each type if I don’t have to. Here is the code:

public class HealthBar : MonoBehaviour
{
    float maxHP;

    void Start()
    {
        maxHP = TryGetComponentInParent<Enemy>().health;
        maxHP = TryGetComponentInParent<RangedEnemy>().health;
        maxHP = TryGetComponentInParent<SuperEnemy>().health;
    }

    void FixedUpdate()
    {
        var hp = TryGetComponentInParent<Enemy>().health;
        var hp = TryGetComponentInParent<RangedEnemy>().health;
        var hp = TryGetComponentInParent<SuperEnemy>().health;
        transform.localScale = new Vector3((hp / maxHP) / 5, 0.125f, 0f);
    }
}

What do I use in place of TryGetComponentInParent ?

Use transform.parent.TryGetComponent, also try to save them to a variable instead of calling GetComponent (almost) every frame

Use transform.parent.TryGetComponent, also try to save them to a variable instead of calling GetComponent (almost) every frame