Actions — how to write them

Actions are the same as delegates and events combined — makes the actual writing far simpler.

Let’s pretend I wanted to create a damage system but I wanted my UI manager to subscribe to the event changes on my health system. If I want an action to occur, I need to access the System library and implement the action this way depending on if it passes in a parameter or now.

Now let’s create a typical damage system.

Now let’s call an Action after health so our UI manager knows to update the health count. We want to use 2 since we are passing in a parameter.

Now on our UI manager, we created an update health script that shows the current health. Whenever the player takes damage, the UI manager will be notified of the event and pull the latest value.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ