unity event code example

Example 1: unityevent

using UnityEngine.Events;

// UnityEvents can also be serialized to the inspector
public class Foo : MonoBehaviour {
  UnityEvent action;
  
  void Start() {
    action = new UnityEvent();
    action.AddListener(() => { Debug.Log("Hello world!"); });
  }
  
  void Update() {
    action.Invoke();
  }
}

Example 2: unity event

The Event System is a way of sending events to objects in the application based on input, be it keyboard, mouse, touch, or custom input. The Event System consists of a few components that work together to send events.

Tags:

Misc Example