PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > Unity3D教程 > 正文

    Unity 发送消息sendMessage

    作者:张志勇来源:原创浏览:时间:2020-09-30 00:07:50我要评论
    导读:创建一个发送者Cube,创建脚本CubeA.cs创建一个接收者Sphere,创建脚本SphereA.csCubeA中发送消息public Game sendOb;void Update(){i...

    创建一个发送者Cube,创建脚本CubeA.cs

    创建一个接收者Sphere,创建脚本SphereA.cs

    CubeA中发送消息

    public Game sendOb;

    void Update(){

    if(Input.GetMouseButtonDown(0)){

    //DontRequireReceiver没有接收者也不会报错

    //myTestAction是方法,接收者实现

    sendOb.SendMessage("myTestAction",null,SendMessageOptions.DontRequireReceiver);

    }

    }

    在接收者SphereA中写myTestAction方法

    void myTestAction(){

    Debug.Log("开跑");

    }

    这就是SendMessage消息机制

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-130-5980-1.html
    相关热词搜索:
    上一篇:关于Prefab