- Home /
Question by
slimsami · Mar 31, 2015 at 03:08 PM ·
c#triggerbutton trigger events
event trigger error
Hi, i would like to add a trigger on a button, but i have a null referenc exception. i tried to be as close as possible to this example but it doesn't work : http://answers.unity3d.com/questions/854251/how-do-you-add-an-ui-eventtrigger-by-script.html here is my code
lcurrentButton.AddComponent<EventTrigger>();
EventTrigger trigger = lcurrentButton.GetComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.Drag;
entry.callback.AddListener( (eventData) => { Swipe_mouse(); } );
trigger.delegates.Add(entry);
the swipe_mouse contains just a debug log for now:
public void Swipe_mouse()
{
print ("swipe_start");
}
here is the error i have on the console: NullReferenceException: Object reference not set to an instance of an object
i don't know what the error is, becaus the trigger is created and i can even see it on the inspector.
Thanks
Comment