Cannot call trigger-event when dragging object via touch
I'm developing a 2D mobile game. In my scene I have a Panel-GO, which holds a Text-GO as child and the child is placed in center of the panel. Both have a Box Collider 2D Component and the Panel-GO has set its Collider as "is trigger". The user can touch and drag the Text-GO anywhere. The goal is to check when the Text-GO gets dragged outside the Panel-GO. I thought I can do so, by simpling calling the OnTriggerExit2D method, which is attached to the Text-GO:
void OnTriggerExit2D(Collider2D col) { Debug.Log ("exit"); }
Somehow the method never gets called. Also I tried all other OnTrigger Methods, none of them workes.
Can someone give me a hint what I'm missing?
Answer by NinjaISV · Nov 18, 2015 at 04:09 PM
You must have a Rigidbody2D on at least one of the objects for void OnTriggerExit2D (Collider2D other) { Debug.Log ("exit"); }
or void OnTriggerEnter2D (Collider2D other) { Debug.Log ("enter"); }
to be called.
http://answers.unity3d.com/questions/592567/why-isnt-my-ontriggerenter2d-function-working.html