using UnityEngine; using UnityEngine.Events; public class ButtonHandler : MonoBehaviour { public UnityEvent onButtonClick; private void OnGUI() { if (GUILayout.Button("Click me")) { onButtonClick.Invoke(); } } }
using UnityEngine; using UnityEngine.EventSystems; public class DragHandler : MonoBehaviour, IDragHandler { public UnityAction onDrag; public void OnDrag(PointerEventData eventData) { transform.position = Input.mousePosition; onDrag?.Invoke(); } }This code creates a drag handler that listens for a mouse drag event and invokes a UnityAction delegate when the drag occurs. The delegate can be used to call other methods or perform actions in response to the drag event. Package library: Unity Engine (UnityEngine.Events)