UnityEvent<T0>
One argument version of UnityEvent.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Class
- Namespace: UnityEngine.Events
- Assembly: UnityEngine.CoreModule
- Inherits from: UnityEventBase
- Implements: ISerializationCallbackReceiver
public class UnityEvent<T0> : UnityEventBase, ISerializationCallbackReceiver
Remarks
Generics are supported, specify a type parameter on initialization as shown in the example. Refer to Configure callbacks in the Inspector for details on configuring callbacks in the Inspector window.
using UnityEngine;using UnityEngine.Events;public class ExampleClass : MonoBehaviour{ UnityEvent<int> m_MyEvent; void Start() { if (m_MyEvent == null) m_MyEvent = new UnityEvent<int>(); m_MyEvent.AddListener(DoSomething); } void Update() { if (Input.anyKeyDown && m_MyEvent != null) { m_MyEvent.Invoke(5); } } void DoSomething(int i) { Debug.Log("Callback called " + i); }}
Note: UnityEvent can also be awaited in any async method.