using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//定义一个委托
public delegate void BoilerLogHandler(string status);
public class EventSent : MonoBehaviour {
//定义自身静态类 用来调用
public static EventSent _instance;
//声明一个事件
public event BoilerLogHandler handler;
void Awake()
{
_instance = this;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnClickEvent()
{
handler("box next door!!");
Debug.Log("事件已发送");
}
}
事件监听
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonitorEvent : MonoBehaviour {
// Use this for initialization
void Start () {
EventSent._instance.handler += ReceiveEvent;
}
// Update is called once per frame
void Update () {
}
public void ReceiveEvent(string str)
{
Debug.Log(str);
Debug.Log("Ass we can");
}
}