Hi!
I have a problem. I have a missile prefab, which instantiates an explosion prebab on destroy. The explosion has a sphere collider. The missiles must ignore the collider of the explosions. I figured out one way to do this, but maybe, I’ll need more to ignore later, not only the layer called “explosion”. So, I decided to read about LayerMasks and I tried to use them. I failed, and I don’t know, what is the problem.
Here is a working code, Layer #9 is “explosion”.
function OnTriggerEnter (other : Collider)
{
if(other.gameObject.layer != 9)
{
Debug.Log("EXTERMINATE!");
Explode();
}
}
At the variable declaration part, I have a line:
var ignoreLayers : LayerMask;
I want to use this for check for more different layers. If the Collider’s layer is not what I selected, explode, otherwise do nothing.
Here is what I tried but didn’t work:
function OnTriggerEnter (other : Collider)
{
if(other.gameObject.layer != ignoreLayers.value)
{
Debug.Log("EXTERMINATE!");
Explode();
}
}
If I select explosion layer, it does nothing, it still executes Explode() function and logs “EXTERMINATE”.
So, how to use LayerMask.value? I didn’t find solution yet.
I dare say I'm missing something, but is there a reason why you're not using Physics settings to prevent the explosions' layer from interacting with the missiles' layer?
– Bonfire-Boy