Showing Health bars at Raycast

Hello beautiful Unity community :slight_smile:
I’ve am fairly new to coding in general, and I have encountered a problem that I am unable to solve. I have been searching for it for few hours but found nothing that would help me.

My problem:
I would like to incorporate enemy health bars into the game, but to show them only when I am looking directly at the enemy.
Something like this:

 var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2, 0));
			if (Physics.Raycast (ray, hit))
			{				
				if (hit.gameObject.tag == "Enemy")
				{
					// activate a bool in EnemyHealth script that will switch on the enemy health bar GUI
				}
			}

I want to show health bar only for the enemy I am looking at. I am aware of the find game object and get component thing, but I need to access only the script of the enemy i am looking at, as i said.
I will also implement there distance check, but that is no problem.

I know it is probably pretty easy thing to do, but as I said i am not very experienced in coding, thanks a lot in advance! <3

looks like a plan of action might be to send a message to the gameobject hit by the ray telling it to show its health bar