CREATE YOUR WORLD
Scripting
UnityEvent
4min
Unity provides UnityEvents to make it easier for users to use C# events and delegates.
UnityEvents are a way of delivering arguments from different objects or passing on a message when certain requirements are met.
To use UnityEvent in ZEPETOScript, you need to declare it in the following format.
First, add an import command as shown below to use the UnityEvent class.
See a sample coupling code for a UnityEvent.
- Script Description
- In the example above, a UnityEvent named ‘mEvent’ is invoked each time a button is pressed, and it executes the ‘Ping’ method when ‘mEvent’ is called.
- Therefore, each time the button is pressed, a message 'Ping' is printed to the console.
If the event that you are about to connect has parameters, you need to add a UnityEvent import command as shown below.
👍 Tips
- UnityEvent$1 is the generic version of UnityEvent
- For instance, if you want to create an event that accepts an integer value, you can use UnityEvent$1<int>
- Please note that the parameter type of UnityEvent$1 follows C#
A sample code when using UnityEvent$1 with parameters is as follows.
You can learn more about UnityEvents by clicking the link below.
Updated 10 Oct 2024
Did this page help you?