I’m having a hard time getting the methods relating to OnCollision or OnTrigger to work properly.
I have a Player1 game object with a rigidbody / BoxCollider2D and I have another game object with no rigidbody and a BoxCollider2D and a script attached to it that is supposed to detect collision:
public bool ColliderOverlap;
void OnCollisionStay2D(Collision2D other)
{
Debug.Log(“Object is within trigger”);
ColliderOverlap = true;
}
void OnCollisionExit2D(Collision2D other)
{
Debug.Log(“Object EXITED”);
ColliderOverlap = false;
}
The script here works ONLY if its game object is NOT set to “Trigger” however I really would prefer to use it as a trigger only (I don’t have much purpose for a solid collider in this instance). I’ve tried the trigger variant of methods such as
OnTriggerEnter2D();
But it doesn’t work either. Does anyone have any advice as to why it won’t work if its set to a “Trigger”? Also, as an aside how exactly are the OnCollision____2D() methods being called since they are not in the regular Update(); method? I find it odd that a method definition is being called without… being called. I’m thinking this has something do with event/listen states but I can’t find much documentation for these methods. Thanks to any help or words of wisdom you could pass along.