【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);
}

在这里插入图片描述

posted @   星空探险家  阅读(5)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示