unity中的委托类似于c/c++中的函数指针
直接上代码
public class delegateTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){//用法1GoodMorning(GoodMorningChinese);//用法2m = GoodMorningEnglish;m();}delegate void MorningLanguage();//声明一个委托 (类似函数指针,指向参数为空,返回值为void的函数)MorningLanguage m; //实例化一个委托的对象void GoodMorning(MorningLanguage ml)//{ml();//参数是空的}void GoodMorningChinese()//某一个参数为空,返回值为void的函数{Debug.Log("早上好");}void GoodMorningEnglish(){Debug.Log("good morning");}
}