sending a sendmessage to a completely different gameobject

so i’m completely new to unity and i have been making little games just to get the hang of it for example i made a platformer game where you have to get to the end then it takes you to the next level. But now i want to make a slightly bigger and more complicated game and i have ran into an issue. at the moment i am trying to get a health and combat system in place and i can’t figure out how to do it because from what i can tell SendMessage only sends to itself and i want my enemy ( a box ) to hurt the player ( capsule ) by sending a message from the damage script that the box has to the health script that the player has surely there has to be a way to do this without doing a massive workaround ???

To send a message, you must have a reference of the target object - its transform, collider, rigidbody etc. A common way to do that in this case is to add a trigger to your weapon, and get the collider hit as the target reference. To add a trigger, child a cube, sphere, capsule etc. to your melee weapon, adjust its dimensions, deactivate the mesh renderer to make it invisible and set Is Trigger, then attach the script below to it:

function OnTriggerEnter(col: Collider){ // col is a reference to the collider hit
    if (col.tag == "Player"){ // if the collider belongs to the Player...
        col.SendMessage("ApplyDamage", 5); // send the message to its owner