public class EventDispatcher : MonoBehaviour
{
public delegate void EventHandler(GameObject e);//定义委托
public event EventHandler MouseOver;
void Start()
{
OnMouseOver();
}
void OnMouseOver()
{
if (MouseOver != null)
{
MouseOver(this.gameObject);//传递参数
}
}
}
public class EventDis : MonoBehaviour {
public GameObject game;
EventDispatcher EventHand;
void Start () {
EventHand = game.GetComponent();
}
void Listener(GameObject g)
{
Debug.Log(g.name);
}
void OnMouseDown()
{
EventHand.MouseOver += Listener;//实现委托
}
}
打赏
扫一扫,请博主喝杯咖啡~