找回密碼
 注冊帳號

掃一掃,訪問微社區

component.sendmessageupwards 發送消息向上

2015-1-5 07:17| 發布者: 楊炎| 查看: 2818| 評論: 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);

}

相關閱讀

文章點評
相關文章
女校游泳队彩金