Home » , , » C# DELEGATES IN UNITY 3D TUTORIAL SERIES PART 1

C# DELEGATES IN UNITY 3D TUTORIAL SERIES PART 1

FutureBrains

A delegate is a type of function which acts like data types just like int and float are value or number types. Delegates can be a little weird in terms of what they do. A delegate gives us the room or the opportunity to actually use a function as a variable.

Delegates allow you to pass data between functions, classes or structs just like parameters or arguments. C# (Csharp) as the ability to actually store a function into a variable just like data. Delegates however have their own rules that you are required to comply with.

The programmer using delegate should ensure that the signature of the variable you are trying to store a function in matches the  signature of the signature of the function you are about to delegate.
CODING TEMPLATE FOR DELEGATES IN UNITY3D
A delegate function is usually declared as follows.

[public class DelExample : MonoBehaviour { 
//we declared a new delegate called MyDelegate. delegate void MyDelegate(); void Start (){ } void Update (){ } }]


For now, we have only declared a delegate function, there is nothing going on for now. There are no arguments in the parenthesis yet.
Stay tuned for PART 2.

0 comments:

Post a Comment

Get Instant Updates

Subscribe to my Newsletter