找回密码
 注册帐号

扫一扫,访问微社区

component.sendmessageupwards 发送消息向上

2015-1-5 07:17| 发布者: 杨炎| 查看: 2860| 评论: 0|原作者: 蛮牛|来自: unity3d脚本manual

摘要: component.sendmessageupwards 向上发送消息functionsendmessageupwards(methodname: string,value: object = null,options:sendmessageoptions=sendmessageoptions.requirereceiver) : voiddescription描述calls th ...

component.sendmessageupwards 向上发送消息

functionsendmessageupwards(methodname: string,value: object = null,options:sendmessageoptions=sendmessageoptions.requirereceiver) : void

description描述

calls the method named methodname on everymonobehaviourin this game object and on every ancestor of the behaviour

sendmessageupwards朝物体和上级父物体发送信息。

游戏物体每一个monobehaviour和每一个behaviour的祖先上调用名为methodname的方法。

the receiving method can choose to ignore the argument 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() {

sendmessageupwards("applydamage", 5.0f);

}

}

// calls the function applydamage with a value of 5

//调用函数applydamage 值为5

sendmessageupwards ("applydamage", 5.0);

// every script attached to the game object

// that has a applydamage function will be called.

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

function applydamage (damage : float) {

print (damage);

}

相关阅读

文章点评
相关文章