Need help implementing dash damage

Dash damage should occur only once on every Entry OR Exit. Also after hitting an enemy the player gets a bonus dash. Here is my code

using UnityEngine;

public class CollisionDetection : MonoBehaviour
{
    
    CombinedPlayerMovement combinedPlayerMovement;
    [SerializeField] GameObject playerC;

    
    private bool hasTriggeredCollider2D = false;     // To make sure score is incremented only on enter or exit

    private void Awake()
    {
        if (playerC != null)
        {
            combinedPlayerMovement = playerC.GetComponent<CombinedPlayerMovement>();
        }

    }

    void Start()
    {
        Debug.Log("Dash To Score");
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        HitOnEnterExit(other);

        if (!hasTriggeredCollider2D && combinedPlayerMovement.isDashing)  // does not flip bool when walking into enemy hitbox
        {
            hasTriggeredCollider2D = true;
        }
    }

    void OnTriggerExit2D(Collider2D other)
    {
        HitOnEnterExit(other);

        if (hasTriggeredCollider2D)          // flip bool for execution on next enter
        {
            hasTriggeredCollider2D = false;
        }
    }

    void OnTriggerStay2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Enemy1") && combinedPlayerMovement.isDashing && !combinedPlayerMovement.canDash) // basically is inside and space key pressed
        {
            Debug.Log("Hit");

            combinedPlayerMovement.canDash = true;

        }
    }

    void HitOnEnterExit(Collider2D other)
    {
        if (!hasTriggeredCollider2D && other.gameObject.CompareTag("Enemy1") && combinedPlayerMovement.isDashing) // Ensure the object has the correct tag
        {
            Debug.Log("Hit");

            combinedPlayerMovement.canDash = true;

        }
    }

}

Is my code alright? Or is the problem in the inspector?

Dash damage should occur only once on every Entry OR Exit.

You forgot to mention what problem you’re actually observing. Remember, it’s forums, so overexplaining a bit often helps. You’re observing more/less damage being applied than expected?

Refer to this chart to make sure you have all of the conditions in place for your trigger messages to occur:

This chart is for 3D physics, but the same basic rules should apply

Oh sorry new here, I’m not getting any messages in the console and I’m not sure if it’s the code that’s wrong as in the logic of when the text is getting passed to the console or the mistake is in the inspector. I tried rebuilding the related objects but still doesn’t work. But even a simple OnTriggerEnter if(isDashing) didn’t show any messages.

When in doubt, add more Debug statements.

    void OnTriggerEnter2D(Collider2D other)
    {
        Debug.Log($"OnTriggerEnter2D {other} with isDashing = {combinedPlayerMovement.isDashing} & hasTriggeredCollider2D = {hasTriggeredCollider2D}");
        HitOnEnterExit(other);

        if (!hasTriggeredCollider2D && combinedPlayerMovement.isDashing)  // does not flip bool when walking into enemy hitbox
        {
            hasTriggeredCollider2D = true;
        }
    }

Do the same in OnExit.

If nothing is logging then your collider is wrong/messed up and you should provide a pic of it.

A fairly common mistake, worth mentioning, is having a 3D collider when you mean to have a 2D collider, so double-check that one. It could also be a Layer or a collider interaction problem as the above post mentioned.