Simple Question, Raycast collision C#

Hey guys, i’v been following some online tutorials on creating a simple FPS game.

I have one script which projects a Ray and checks the tag of the collider that it hits

I have a simple health script “HealthScript” which is attached to an object in my scene. HealthScript has a public function called “AdjustCurrentHealth” which takes an integer.

If the Ray hits a collider with the tag “Player” I want it to use the object’s function “AdjustCurrentHealth” to remove hit points from the HealthScript.

			if(hit.transform.tag == "Player")
				//Instantiate explosion effect
				Instantiate (blasterExplosion, hit.point, Quaternion.identity);
				expended = true;
				//Projectile becomes invisible				
				myTransform.renderer.enabled = false; 
				//Disable projectile's light
				myTransform.light.enabled = false;

Obviously my error is this line : hit.collider.gameObject.HealthScript.AdjustCurrentHealth(-10);

I get an error telling me that UnityEngine.gameObject does not contain a definition for “HealthScript”.

If anyone could help me with this I would be very appreciative.

“HealthScript” is not a variable in a game object. It is a component attached to a game object. So you could do something like:

hit.collider.gameObject.GetComponent< HealthScript >().AdjustCurrentHealth(-10);