I have a 2D game with a handful kinematic objects.
I am checking in OnTriggerEnter2D for IsTouchingLayers but it is acting very odd
This is the Code
private void OnTriggerEnter2D(Collider2D collision)
{
int p=collision.gameObject.layer;
int r = LayerMask.NameToLayer("Ships");
if (collision.IsTouchingLayers(LayerMask.GetMask(new string[] { "Ships" })))
//if(p==r)
{
Destroy(this.gameObject);
}
}
So this code does not work as it is, the Orb (which this script is attached to) is on layer “Items” and the ship (which is what it has collided with is on layer “Ships”.
However if I change the ship to layer “Items” (and obviously change the code to match) then IsTouchingLayers does indeed then work. But it does not work if the ship is on any other layer. So IsTouchingLayers only appears to be working for objects on the same layer…
If I comment out the IsTouchingLayers If statement and uncomment the p==r If statement then the code works fine.
The Collision Matrix has all boxes ticked.
I am using version 5.5