定义委托及事件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public delegate void KaiShiEventHandler(string name);//定义委托
public class AppMain : MonoBehaviour {
public static event KaiShiEventHandler kaishi;//事件
public Button but;
public int i = 0;
// Use this for initialization
void Start () {
but.onClick.AddListener(OnClick);
}
public void OnClick()
{
kaishi("ddddddddd~");
}
// Update is called once per frame
void Update () {
}
}
实现事件监听+=
(事件取消监听为-=)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeApp : MonoBehaviour {
// Use this for initialization
void Start () {
AppMain.kaishi += kaishi;
}
public void kaishi(string name)
{
Debug.Log("开始~~~~"+name);
}
// Update is called once per frame
void Update () {
}
}