找回密碼
 注冊帳號

掃一掃,訪問微社區

component.sendmessage 發送消息

2015-1-5 07:07| 發布者: 楊炎| 查看: 2661| 評論: 0|原作者: 蠻牛|來自: unity3d腳本manual

摘要: component.sendmessage 發送消息functionsendmessage(methodname: string,value: object = null,options:sendmessageoptions=sendmessageoptions.requirereceiver) : voiddescription描述calls the method named met ...

component.sendmessage 發送消息

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

description描述

calls the method named methodname on everymonobehaviourin this game object.

sendmessage朝本級別物體的多個腳本發送信息。

游戲物體每一個monobehaviour上調用名為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() {

sendmessage("applydamage", 5.0f);

}

}

// calls the function applydamage with a value of 5

//調用函數applydamage 值為5

sendmessage ("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);

}

相關閱讀

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