I made a melee combat system for my game. The code looks like this:
var hit:RaycastHit;
if(Physics.Raycast(transform.position,transform.forward,hit)) {
if(hit.distance<=2.0) {
Debug.LogError("Hit!");
Debug.LogError(hit.collider.tag);
if(hit.collider.tag=="Enemy") {
Instantiate(bloodFX,hit.transform.position,transform.rotation);
hit.transform.SendMessage("ApplyDamage",25,SendMessageOptions.DontRequireReceiver);
}
}
}
However, when an object with the tag "Enemy" stands in front of a "Tree" object, the log tells me that it's hitting the tree tag and not the enemy. What am I doing wrong here? The collision boxes are all correct.
Thanks!
P.S. This is for the ludum dare that ends in 4 1/2 hours so I have to fix this quickly.