This works fine:
gameObject.GetComponent<UnityEngine.UI.Button>().onClick.AddListener(OnClick);
But this doesn’t:
gameObject.GetComponent<UnityEngine.EventSystems.EventTrigger>().OnPointerEnter.AddListener(OnHoverEnter);
It gives: error CS0119: Expression denotes a method group', where a
variable’, value' or
type’ was expected
It works fine if I add the listener in the inspector, but if it’s in a prefab that I’m loading at runtime, then unless I’m mistaken I need to add the listener at runtime as well.
EventTrigger.OnPointerEnter() is a method so there is no AddListener there.
There appears to be an exposed field on EventTrigger:
public List<EventTrigger.Entry> delegates
so maybe you just register additional stuff through there.
Entry is defined as:
[Serializable]
public class Entry
{
public EventTrigger.TriggerEvent callback;
public EventTriggerType eventID;
public Entry();
}
inside the EventTrigger
The snippet in the following post works:
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.