I am using raycasthit to shoot a GameObject. I am able to do damage to the GameObject(GO) with the sendmessage function so I know I am getting the GO. I am wanting to get the GO so I can pull a variable that holds the HP of the GO so I can update the HUD. It will most likely be a instantiate prefab that has about 10 clones.
This is the code that I am working with.
var rayMouse = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitMouse : RaycastHit;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (rayMouse, hitMouse, 100))
{
Debug.DrawLine (rayMouse.origin, hitMouse.point);
hitMouse.collider.SendMessage("Damage", 50);
//GameObject.Find("g_targetHP").guiText.text =
var hitTarget : String = hitMouse.collider.GameObject.name;
print(hitTarget);
}
}
I either need the variable or be able to call my GetHp() function on the GO from the Raycasthit. I am open to any rewrites if it get the job done.