개발메모/Unity

OnTriggerEnter2D 함수가 동작하지 않는 이유

RideAbove 2023. 8. 7. 16:52
반응형

OnTriggerEnter2D 의 공식 문서를 보면 다음과 같은 설명을 볼 수 있다.

Description

Sent when another object enters a trigger collider attached to this object (2D physics only).

Further information about the other collider is reported in the Collider2D parameter passed during the call.

This message is sent to the trigger Collider2D and the Rigidbody2D (if any) that the trigger Collider2D belongs to, and to the Rigidbody2D (or the Collider2D if there is no Rigidbody2D) that touches the trigger.

Note: Trigger events are only sent if one of the Colliders also has a Rigidbody2D attached. Trigger events are sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions.

 

결론: 여기서 Note 부분을 보면 trigger를 통해 충돌하는 두 물체중 하나가 Rigidbody2D를 갖고 있어야 한다는 내용을 확인할 수 있다.

 

 

출처: https://discussions.unity.com/t/why-isnt-my-ontriggerenter2d-function-working/89227

 

why isn't my OnTriggerEnter2D() function working?

guys im struggling over an hour on the 2d collision event. Currently I have 2 sprite’s each have a 2d boxcollider and are triggers. I have set the tag of one of the sprite’s to “player” but it still doesn’t work. I have already checked everything

discussions.unity.com

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html

 

Unity - Scripting API: MonoBehaviour.OnTriggerEnter2D(Collider2D)

Further information about the other collider is reported in the Collider2D parameter passed during the call. This message is sent to the trigger Collider2D and the Rigidbody2D (if any) that the trigger Collider2D belongs to, and to the Rigidbody2D (or the

docs.unity3d.com

 

반응형