Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# delegate

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DelegateDemo : MonoBehaviour {
	public delegate void Del(string msg); 

	void Start(){
		Del SampleDel;

		SampleDel = PrintMsg;
		SampleDel += Debug.Log; //using plus sign we can subscribe multiple methods to trigger events. 
		SampleDel("Hello Shrinath..."); //when this is called, all the methods subscribed to this delegate gets called
	}

	void PrintMsg(string msg1){
		Debug.Log ("msg : " + msg1);
	}
}
Source by learningneverendstech.com #
 
PREVIOUS NEXT
Tagged: #delegate
ADD COMMENT
Topic
Name
3+7 =