【Unity】API学习-->消息系统
发送消息
-
SendMessage (string methodName , object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver)- 传给自身及自身组件
methodName字符串 要调用方法的名称value要传递的参数options如果目标对象上不存在该方法,是否应该引发错误?
-
BroadcastMessage (string methodName, object parameter= null, SendMessageOptions options= SendMessageOptions.RequireReceiver)- 广播消息 向下按层级发送,包括自己
-
SendMessageUpwards (string methodName, object value= null, SendMessageOptions options= SendMessageOptions.RequireReceiver);- 向上按层级发送消息,包括自己
父类子类接受消息顺序


void Start() {
//发送消息
SendMessage("GetMeg",100.0f);
}
//接受消息
void GetMeg(float num) {
Debug.Log("接收到了消息:"+num);
}

本文来自博客园,作者:星空探险家,转载请注明原文链接:https://www.cnblogs.com/PuppetLazy/p/17840925.html

浙公网安备 33010602011771号