So I been trying to make a gun using Physics.Raycast and up until now it has seemed perfect. But now I’m trying to use tags so that whenever you shoot something it gets destroyed, and the collider doesn’t seem to be showing the right tags.
Here’s my code:
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit))
{
Instantiate(hitEffect, hit.point, Quaternion.Euler(Vector3.zero)));
Debug.Log("Tag: " + hit.collider.gameObject.tag);
if(hit.collider.gameObject.CompareTag("Enemy"))
Destroy(hit.collider.gameObject);
}
I’ve tried several variations like hit.collider.tag and hit.collider.gameObject.tag == “Enemy”, but still no luck. I’m using Unity 4.