Skip to content

Commit 55e1544

Browse files
committed
Add an example of how to define a UnityEvent
1 parent 3d13622 commit 55e1544

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

Documentation~/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,27 @@ To trigger the event follow the same steps as with _Simple Scriptable Event_. Ho
7373
<img src="scriptable-event-raise-dynamic.png"/>
7474
</p>
7575

76-
Alternatively you can trigger the event via code:
76+
This example shows how to trigger a _Scriptable Event_ from a built-in Unity component, however you might want to invoke these events from your classes. To do so, define a [Unity Event] with an appropriate type in the following way:
77+
```cs
78+
using UnityEngine;
79+
using UnityEngine.Events;
80+
81+
public class ExampleUnityEventUsage : MonoBehaviour
82+
{
83+
[SerializeField]
84+
private UnityEvent<float> onValueChanged;
85+
86+
private void Start()
87+
{
88+
// Your argument value.
89+
var value = 1.0f;
90+
91+
onValueChanged.Invoke(value);
92+
}
93+
}
94+
```
95+
96+
Alternatively you can trigger the event via code if you prefer not to use [Unity Event] functionality:
7797
```cs
7898
using ScriptableEvents.Events;
7999
using UnityEngine;

0 commit comments

Comments
 (0)