Created
May 30, 2013 06:02
-
-
Save s2kw/5675959 to your computer and use it in GitHub Desktop.
Learn Delegate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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