Hi.
I added a Sphere collider to Empty GameObject and set it to child of enemy GameObject.
now I used below code for fire to enemy and reduce health:
public class Gun : MonoBehaviour {
RaycastHit hit;
public Camera fpsCam;
public float range = 100f;
float Health = 100f
void Update ()
{
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
if (hit.transform.name == "Enemy")
{
Health -= 10f;
}
}
}
}
but problem is when I shoot to enemy and gun ray collide to Sphere collider, make reduce enemy health. while I want when gun ray collide to enemy body, reduce health.
anyone know how can fix this problem?
Thanks.