There is a OnTriggerEnter2D function, it triggers correctly
private void OnTriggerEnter2D(Collider2D other)
{
if (!assailables.Contains(other.transform) && other.GetComponent<IAssailable>()!=null)
{
Debug.Log(other.transform.position);
assailables.Add(other.transform);
}
}
But when i try to verify it again in update function with Collider2D.overlapCollider, it will return 0.
CompositeCollider2D groundArea = GetComponent<CompositeCollider2D>();
Debug.Log(groundArea.OverlapCollider(new ContactFilter2D(), new Collider2D[] {assailables[i].GetComponent<Collider2D>() }));
enter image description here
I don’t know why it can trigger OnTriggerEnter2D but returns 0 when I call OverlapCollider, is it correct?
The compositeCollider2D is dynamic, so I want to check it again and removing from assailables when it has not been in the compositeCollider2D.
New contributor
user26857367 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.