Melee Attack System

I have been learning to work with unity for a while now both C# and JavaScript but on my recent project the one thing I havent yet figured out is an attack system for my current project.
All I need to get moving agin is an ttack system shown below also please dont just post a sctipt and be like “Here This Works” try to explain why it works how it works and what makes it work.

Health Script

var curHealth : int = 100;
var maxHealth : int = 100;

var healthtext : GUIText;
 
 
 
function Start () {
 
 
healthRegen();
 
}
 
 
 
 
 
function Update () {
 
 
healthtext.text = curHealth + " / " + maxHealth;
 
 
if(curHealth < 0 ) {
 
curHealth = 0;
 
 
}
 
 
if(curHealth > 100) {
 
 
curHealth = 100;
 
 
}
 
 
 
if(Input.GetKeyDown("e")) {
 
curHealth += 10;
ManaScript.curmana -= 20; 
}
 
 
 
}
 
 
 
 
function healthRegen () {
 
 
for(i=1;i>0;i++) {
 
 
 
yield WaitForSeconds(1.5);
 
if(curHealth < maxHealth) {
 
curHealth++;
 
}
 
 
}
 
 
}

Mana Script

#pragma strict
	

    static var curmana : int = 100;
    var maxmana : int = 150;
     
    var manatext : GUIText;
     
     
    InvokeRepeating("manaRegen", 2, 5.0);
      
    function Start () {
     
    
     
    }
     
     
     
     
     
    function Update () {
     
     
    manatext.text = curmana + " / " + maxmana;
     
     
    if(curmana < 0 ) {
     
    curmana = 0;
     
     
    }
    
     
     
    if(curmana > 100) {
     
     
    curmana = 100;
     
     
    }
     
     
     
    if(Input.GetKeyDown("1")) {
     
    curmana -= 10;
     
    }
     
     
     
    }
     
     
     
     
    function manaRegen () {
     
    curmana += 5;
     
     
     
    }

For the first, use an OverlapSphere and sort through the colliders comparing distance and direction.
For the second, use an OverlapShere fairly vanilla.

Many examples are out there showing the exact syntax, variations, other alts, tuts, vids, YouTube vids, etc.