Hey,
I’m trying to add an event type to an event trigger via script. In my main class LoadLevel I’m calling the function SetClickEvent() in the class LoadParts (removed unnecessary parts and transformed to pseudocode)
public class LoadLevel : MonoBehaviour {
void SpawnParts()
{
loop()
{
loadP.SetClickEvent();
}
}
With SetClickEvent() I create a new EventTrigger.Entry() with the eventID: PointerDown and the function that should be called partSprite.GetComponent<RotateP>().RotatePart((PointerEventData)data);
Then I’m adding this entry to my EventTrigger component.
public class LoadParts {
public GameObject partSprite;
public void SetClickEvent()
{
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener((data) => {
partSprite.GetComponent<RotateP>().RotatePart((PointerEventData)data);
});
partSprite.GetComponent<EventTrigger>().triggers.Add(entry);
Debug.Log("Added event");
}
}
When I test the code I can see that the entry with the eventID gets added to the EventTrigger but without the listener:
What am I doing wrong? Btw. I’m getting no errors and the code already worked when the LoadLevel and LoadParts class were merged together.
Thanks in advanced,
Tobias