How to I access (or read) another game object's enums through OnTrigger collisions?

Hi, I just have a quick question.

So I’m making a 2D game and to make it easier on myself in the long-run I wanted to create a system where I input the various properties of an attack and when my player character is hit it will react according to what I’ve put as it’s responses.

My problem is that I don’t exactly know how to access the properties of an object while it is colliding in the code. Nor do I know if that it is actually the best way to go about it.

Firstly, I want to be able to differentiate between a light and a heavy attack so that a different amount of health can be taken from the player character, and if it was just two different attack types I would used scripts but I want there to be several different parameters that the player can react to.

Here is what my Enemy Attack Parameter Script looks like:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum EnemyAttackStrength
{
    light,
    heavy,
}


public enum EnemyAttackType
{
    melee,
    ranged,
    special,
}

public enum EnemyAttackElement
{
    none,
    fire,
    ice,
    electric,
    crystal,
    poision,
}

public class EnemyAttack: MonoBehaviour
{
    public EnemyAttackStrength thisAttackStrength;
    public EnemyAttackType thisAttackType;
    public EnemyAttackElement thisAttackElement;
}

And here is the excerpt where I’m trying to have the player detect what enum the enemy attack is:

 private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == ("Enemy"))
        {
            if (collision.gameObject.GetComponent<EnemyAttack>()) //obviously a mockup
            {
                if (thisPlayerInvulnerability == playerInvulnerability.vulnerable)
                {
                    health = health - 5;
                    player.tookDamage = true;
                    ChangeVulnerability(playerInvulnerability.invulerable);
                    StartCoroutine(InvincibilityTimer());
                }
                else if (thisPlayerInvulnerability == playerInvulnerability.invulerable)
                {
                    health = health - 0;
                    player.tookDamage = false;
                }
            }
        }

Thank you for anyone willing to help, I really appreciate it!

Just assign the collision.gameObject.GetComponent() to an EnemyAttack local variable. Then you access it via that variable.

Just for example, here is my code in my game for a playercontroller when the player activates a grab:

public void Grab(bool grabAll = false)
    {
        Collider2D[] potentialPickups = Physics2D.OverlapCircleAll(GrabPosition.position, GrabRadius, GrabLayers);
        if (potentialPickups != null && potentialPickups.Length > 0)
        {
            Collider2D firstPotentialPickup = potentialPickups[0];
            ResourceNodeController rnc = firstPotentialPickup.GetComponent<ResourceNodeController>();
            if (rnc != null)
            {
                ResourceNode rn = GameCore.Current.Resources[rnc.ResourceNodeID];
                if (rn.HarvestHealth == 0)
                {
                    InventoryContainer results = rnc.GrabResource();
                    if (results != null)
                    {
                        PlayerData.Current.Inventory.MergeContainers(results);
                        if (!results.IsEmpty())
                            PlayerData.Current.ToolBar.MergeContainers(results);
                        if (!results.IsEmpty())
                        {
                            GameObject go = Instantiate(GameResources.Current.LootBagPrefab, transform.position, Quaternion.identity);
                            InventoryContainerController lc = go.GetComponent<InventoryContainerController>();
                            lc.InventoryContainer_var = results;
                            lc.Initialize();
                        }
                    }
                }
            }
            else
            {
                IInteractableElement iie = firstPotentialPickup.GetComponent<IInteractableElement>();
                //InventoryContainerController lc = firstPotentialPickup.GetComponent<InventoryContainerController>();
                if (iie != null)
                {
                    if (grabAll && iie is InventoryContainerController icc)
                    {
                        PlayerData.Current.Inventory.MergeContainers(icc.InventoryContainer_var);
                        if (!icc.InventoryContainer_var.IsEmpty())
                            PlayerData.Current.ToolBar.MergeContainers(icc.InventoryContainer_var);
                    }
                    iie.DisplayUI();
                }
            }
        }
    }

My god you did it… Thank you so much