Hit Collision with exceptions


I am trying to make a projectile, which destroys itself upon impact. The problem is ,i need it to ignore some objects ,such as the character controllers collider, and i am flummoxed why it wont work.
My solution is:

function OnCollisionEnter ( hit : Collision){

if (hit.gameObject.tag !== "MainCamera" || hit.gameObject.tag !== "DontDestroyProjectiles" ) {

Destroy (gameObject);



Also i have been fiddling with Physics.IgnoreCollision ,without results. Maybe it would work with that, and if someone found a way with this ,please explain it troughly, becouse im pretty dense.

Any help would be greatly appriciated.

Use physics layers if you want to ignore collisions between types of objects. It doesn’t require coding and it will be faster as the collision will not take place and therefore no code will be run.

I find a bit of issue in your coding. I don’t know if that’s the cause of the problem. You should use “!=” instead of “!==” . Also, since this script is for projectile, I suggest you use Trigger because Collision sometimes causes slowness to the object.