My script is sending a raycast message and I wanted my raycast to be able to detect what object it hit. it seems to be able to detect the gameObject with the tag “Body” easily because it isn’t a child object, however the component I’m trying to find below that is a child of other child objects so I’m not really sure how to reference it. I know I can use hit.transform.Find(“path/etc”), but that doesn’t get the tag. Here’s my script if it helps.
void Raycast()
{
Ray rayDirection = Camera.main.ScreenPointToRay(new Vector3((Screen.width / 2),(Screen.height / 2)));
{
RaycastHit hit;
{
if(Physics.Raycast (rayDirection, out hit))
{
Distance = hit.distance;
{
if (animation.IsPlaying ("Fire"))
{
if (hit.transform.tag == "Body")
{
print ("bodyhit");
hit.transform.SendMessage ("Bodyhit", SendMessageOptions.DontRequireReceiver);
Debug.DrawLine(transform.position, hit.point, Color.red);
}
if (hit.transform.GetComponentsInChildren) //I'm not sure what to do here
{
Damage += 75;
print ("Headhit");
hit.transform.SendMessage ("Bodyhit", SendMessageOptions.DontRequireReceiver);
Debug.DrawLine(transform.position, hit.point, Color.yellow);
Damage -= 75;
}
}
}
}
}
}
}