Question by
TheSaviour · Aug 25, 2016 at 06:55 AM ·
instantiateprefabmouseclickevent triggering
How do I use an event trigger on an instantiated prefab?
When I use the Pointer Up and Pointer Down triggers on a prefab that is already in the hierarchy, they work fine. But when I try to use the triggers on an instantiated prefab, they don't work.
Any idea how to solve this?
Comment
Answer by mahdiii · Aug 25, 2016 at 02:53 PM
You need to define and callback in the script EventTrigger event_trigger = GetComponent(); event_trigger.triggers[0].callback.AddListener((eventData) => { yourMethod1(); }); event_trigger.triggers[1].callback.AddListener((eventData) => { yourMethod2(); });
triggers[0] is defined in the inspector,(for example it is pointerup) triggers[1] is defined in the inspector,(for example it is pointerdown)