How would this EventTrigger look in c#

Hello, i want to do this from scripting side:

A) Take my GameObject Buttontop add an event Pointer Enter. Call a function RectTransform.parent to set the Parent to Panel2

B) Not call RectTransform but my own function Myfunc with the argument Myarg

May someone write me a short example script please.

Here in the picture you see what i want to do from scriptside:


First, remove the Event Trigger component, then add a new script that implements the IPointerEnterHandler interface. This interface forces you to implement OnPointerEnter. You can do whatever you want inside that method, you can call a method in the same script or a method in another script. If the method is in another script just add a member to set that reference in the inspector or find that however you want.

Something like this should work:

sing UnityEngine;
using UnityEngine.EventSystems;

public class GameController : MonoBehaviour, IPointerEnterHandler {

    OtherScript otherComponent; //set this in the inspector

    void PrivateMethod() {
        //do something

    void OnPointerEnter() {

The event system will detect when the pointer enters the game object and will call OnPointerEnter on any script that implements it.

If you want to keep the EventTrigger to add events dynamically at runtime it gets a litter more complex, so if this works for you just do it this way.