
Member-only story
Delegates and Events Part 1: Void Type
There is a powerful combination to be found with delegates and events, and they are very useful together when using Unity’s new input system. Let’s dive in and take an in depth look into how to declare and use delegates and events.
Delegates
Delegates are like variables that hold one or more methods. You can declare a delegate by using the keyword delegate, followed by it’s method signature. The method signature is the type of method that you want your delegate to hold. This could be a void type method with or without parameters, or even a return type method. After defining the method signature for your delegate, you can then declare a variable to store the delegate. The variable type must match the name and the method signature of the delegate. Let’s look at two examples, one with parameters and one without.

These each have a corresponding method. What’s important to note here, is the matching method signatures. The Update Color method is a void type method with a parameter that takes a color variable. The Task Completed method is also a void type method that has no parameters.