Hit Tags

Normally, while writing hit listeners, such as the logic we have written in the previous section, you would want to behave differently according to the hit object's layer or tag. For instance, if it's tagged as "Metal", you'd spawn a metal particle, but if it's tagged "Body" you would spawn a blood particle. The HitListenerSpawnParticle.cs script under the folder InanEvin>Realistic Sniper and Ballistics>src>Hits is doing exactly this. However, introducing tags such as Metal, Dirt, Body etc. for the demo scenes isn't a good idea, as we want to avoid modifying the project settings of the users as much as possible. That's why, under the same folder you can see scripts such as HitTagBody.cs, HitTagMetal.cs, HitTagWood.cs, so instead of checking the hit object's layer or tag, we simply check whether they contain any of these tag MonoBehaviors or not, and spawn particles accordingly in HitListenerSpawnParticle.cs. In your own project, you might want to clearly assign reasonable tags to your objects, so you can check their tags instead of checking for component existence.

Last updated