Skip to content

Instantly share code, notes, and snippets.

@s2kw
Created May 30, 2013 06:02
Show Gist options
  • Save s2kw/5675959 to your computer and use it in GitHub Desktop.
Save s2kw/5675959 to your computer and use it in GitHub Desktop.
Learn Delegate.
using UnityEngine;
using System.Collections;
public class DelegateTest : MonoBehaviour {
delegate void someDelegate();
public class Person{
private string name;
public Person( string naming ){
name = naming;
}
public void SayName(){
Debug.Log("my name is"+name);
}
}
public class delegateTest{
public void method()
{
Person p1 = new Person("Apple");
Person p2 = new Person("Orange");
someDelegate dlgt = p1.SayName;
dlgt += p2.SayName;
dlgt();
}
}
// Use this for initialization
void Start () {
delegateTest test = new delegateTest();
test.method();
}
// Update is called once per frame
void Update () {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment