How UnityAction: event System works.Action

Found in Unity Docs: https://docs.unity3d.com/ScriptReference/Events.UnityAction.html

It seems to have realized that it can store variables, and the type is void. But I didn't fully understand how it works, and whether it can do anything else. These are:

  • event System.Action
  • Delegates
Author: Suvitruf - Andrei Apanasik, 2020-01-05

1 answers

Store variables, and type void

UnityAction - this is, in fact, a delegate (UnityAction(), in general, void delegate). Simply put, it's a colback. If you need to subscribe to an event, then UnityAction should be used.

In fact, in the example link, everything is explained:

// добавление подписчика
m_MyFirstAction += MyFunction;
// подписка на событие нажатия кнопки
// когда кнопка будет нажата, то все подписчики из m_MyFirstAction получат уведомление
m_AddButton.onClick.AddListener(m_MyFirstAction);
 2
Author: Suvitruf - Andrei Apanasik, 2020-01-05 13:16:07