This question was
closed Jun 02, 2017 at 05:43 PM by
KhrisSutherland for the following reason:
Found a solution.
Question by
KhrisSutherland · Jun 01, 2017 at 06:24 PM ·
raycastvariablescripting beginnerfunction
Changing a variable in another script with raycast
Here's the Raycast function I'm using.
void RaycastFunction()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Enemy") {
print ("Struck an enemy");
hit.collider.gameObject.
}
}
What I'm trying to do, is have a "Health" variable in a script (called Statistics), in another game object, reduce by 50 each time it is hit by the raycast. I don't know what to put after "hit.collider.gameObject._". I've looked at numerous tutorials, but none of them really helped.
Comment