I have a gameobject called "Target" which contains the animator controller, I have a capsule collider on a gameObject in the tree for Target called Robot. The current script I have is attached to a gun object and is as follows and destroys the object and it disappears when the raycast collides with the collider, and prints out the tag and name of the collider it hit(just for testing purposes):
RaycastHit hit;
if (Physics.Raycast (fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) {
if (hit.transform.tag == "Target") {
print(hit.transform.gameObject.name);
print(hit.transform.gameObject.tag);
hit.transform.gameObject.GetComponent<Animator>().SetBool("isHit", true);
Destroy(hit.transform.gameObject);
target.getTargets = GameObject.FindGameObjectsWithTag ("Target");
target.targetCount = target.getTargets.Length -1;
target.countText.text = (target.targetCount ).ToString ();
}
GameObject impact = Instantiate (impactEffect, hit.point, Quaternion.LookRotation (hit.normal));
Destroy (impact, 1f);
}
}
However when i active the animator controller the raycast no longer seems to hit the collider at all, the name nor tag is printed out. I have a isHit variable in the animator that is supposed to play a death animation when set to true and then disappear as it should when no animator is present but I'm not sure how to access the animator on the main object from the child object that has the collider.