2D sidescroller health bar

I am new to coding and Unity

I have the health bar appearing on my screen, but I am not sure how to link the Health script of the health bar to my player script and my player’s health script. Simply, I want to make it so when my player gets shot my health bar will lose a heart. The health script of the player’s is also linked to the enemy.

My health bar is made with a GUITexture heart

I used this video for the health bar and now I need to figure out how to incorporate the health bar script with my health script and and player script

I get the impression that I need to include some lines of code from my health bar script or link it/reference it some how in my player script

my code is in the link in the same question that I asked on stack overflow…

I can not go over all the scripts there, but as a simple way;

int = numberOfLives;
public List<GUITexture> hearts; // or array, does not matter, you should assign GUITexture objects from the inspector, 5 of them if you have a max of 5 lives
void HealthBar(){
    for(int i = 1; i <= hearts.Count; i++){
       if(i <= numberOfLives){
            hearts*.gameObject.SetActive(true);*

} else {
hearts*.gameObject.SetActive(false);*
}
}
}

The simple way to get Script A to interact with Script B is:

On Script A

public ScriptBName scriptBName;

in the Inspector, a field will appear called scriptBName (for the gameobject Script A is attached to)

Drag/drop the gameobject that Script B is attached to into that field; voila

Now in Script A you can access (public) fields, methods etc on Script B by doing something like

if(scriptBName.someVar) //

or

if(PlayerGotSmacked)
scriptBName.health --;