component.broadcastmessage 广播消息

2015-1-5 03:17| 发布者: 杨炎| 查看: 2069| 评论: 0|原作者: 蛮牛|来自: yzc88亚洲城脚本manual

摘要: component.broadcastmessage 广播消息functionbroadcastmessage(methodname: string,parameter: object = null,options:sendmessageoptions=sendmessageoptions.requirereceiver) : voiddescription描述calls the me ...

component.broadcastmessage 广播消息

functionbroadcastmessage(methodname: string,parameter: object = null,options:sendmessageoptions=sendmessageoptions.requirereceiver) : void

description描述

calls the method named methodname on everymonobehaviourin this game object or any of its children.

游戏物体每一个monobehaviour和它的全部子物体上调用名为methodname的方法。

通俗的解释:

broadcastmessage朝物体和所有子物体发送消息。

对一个物体及其所有子物体,进行消息的广播,如果其中任何子物体上贴有脚本,而脚本中有相应的处理此消息的函数,则invoke调用之。

the receiving method can choose to ignore parameter by having zero arguments. if options is set tosendmessageoptions.requirereceiveran error is printed when the message is not picked up by any component.

接受消息的此方法(函数)可以通过设置没有引用参数表来忽略传过来的消息中的参数。如果选项option中设置成了sendmessageoptions.requirereceiver,那么当没有任何脚本组件接受此消息时,一个相应的错误会弹出来

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

void applydamage(float damage) {

print(damage);

}

public void awake() {

broadcastmessage("applydamage", 5.0f);

}

}

// calls the function applydamage with a value of 5

//调用函数 applydamage 值为5

broadcastmessage ("applydamage", 5.0);

// every script attached to the game object and all its children

// that has a applydamage function will be called.

//附加到游戏物体的每个脚本和全部的子物体,有一个applydamage函数将被调用

function applydamage (damage : float) {

print (damage);

}

相关阅读

文章点评
相关文章