- Home /
Question by
toishaanpatel · Jul 24, 2020 at 06:11 PM ·
raycastcollidertransformraycasthit
RaycastHit: What is the difference between hit.transform.tag and hit.collider.tag?
I am trying to make the player shoot a raycast and detect if hit the enemy's sphere collider. What should I use and which would work better? The objects both have tags on them.
Comment
Answer by SpiderManAW · Jul 24, 2020 at 09:18 PM
I personally use hit.collider.tag, hit.collider.tag is to collide with something.
a script from one of my games:
if (rayHit.collider.CompareTag("Sphere"))
{
Instantiate(Dead, transform.position, transform.rotation);
Destroy("Sphere")
}
i Havent tested it in a long time though, i hope it helps, Basically on raycast hit, Paste dead body(Sphere) then destroy sphere and keep dead.