- Home /
Question by
shruikan · May 12, 2016 at 01:53 PM ·
eventtriggerseventsystemnameevent triggering
Method name expected when adding Event Trigger using script
Hi, I'm getting error:
error CS0149: Method name expected
in line:
UnityAction <BaseEventData> call = new UnityAction<BaseEventData>(this.gameObject, TeleportPlayer);
when I try to add new event using script (custom inspector that automatic adds new event).
void AssignTrigger()
{
EventTrigger trigger = GetComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerUp;
entry.callback = new EventTrigger.TriggerEvent();
UnityAction<BaseEventData> call = new UnityAction<BaseEventData>(this.gameObject, TeleportPlayer);
entry.callback.AddListener(call);
trigger.triggers.Add(entry);
}
public void TeleportPlayer()
{
}
Comment
According to the docs you should specify both args types in your angles.
Wow, being on mobile makes this a chore :p
Answer by Link0n3 · May 12, 2016 at 04:06 PM
Have you tried with a lambda expression for the delegate?
entry.callback.AddListener((x)=>{TeleportPlayer();});
I added your line replacing my seventh and removing the sixth. Now there is no error but it only adds empty PointerUp event :(
Your answer
![](https://koobas.hobune.stream/wayback/20220612080646im_/https://answers.unity.com/themes/thub/images/avi.jpg)