Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Delegates in Unity

    • 0
    • 5
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 808
    Comment on it

    DELEGATES IN UNITY:

    A delegate is a reference pointer to a method. When it is called, it gives notification to all methods that reference the delegate. It allows us to treat a method as a variable and pass method as a variable for a callback. The basic idea of a delegate is exactly the same as a subscription magazine. Anyone can subscribe to the services and they will receive the update at the right time automatically.

     

    TYPES of Delegate:

    1.Single Delegate:- It can reference to only single method at a time.

    2.Multicast Delegate:- It can store the reference of multiple methods at a time.

     

    SYNTAX :

    //Defining Delegates

    public delegate void OnMouseClickDelegte();

    public static OnMouseClickDelegte mouseClickDelegate;

     

    //Subscribing to a delegate

    // eg. of singlecast delegate

    mouseClickDelegate = myExampleMethod;

    //eg. of multicast delegate

    mouseClickDelegate += myExampleMethod;

    mouseClickDelegate +=myAnotherExampleMethod;

     

    //Calling delegates

    mouseClickDelegate();

     

    //UnSubscribing to delegates

    mouseClickDelegate -= myExampleMethod;

    mouseClickDelegate -=myAnotherExampleMethod;

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: