找回密碼
 注冊帳號

掃一掃,訪問微社區

collider.ontriggerstay 逗留觸發器

2015-1-4 18:27| 發布者: 楊炎| 查看: 1927| 評論: 0|原作者: 蠻牛|來自: unity3d腳本manual

摘要: collider.ontriggerstay 逗留觸發器functionontriggerstay(other: collider) : voiddescription描述ontriggerstay is calledalmostall the frames for everycolliderotherthat is touching the trigger.每個碰撞器ot ...

collider.ontriggerstay 逗留觸發

functionontriggerstay(other: collider) : void

description描述

ontriggerstay is calledalmostall the frames for everycolliderotherthat is touching the trigger.

每個碰撞器other觸動觸發器,幾乎在所有的幀ontriggerstay被調用。通俗的說,

每個碰撞器從進入觸發器那一刻到退出觸發器之前,幾乎每幀都會調用ontriggerstay。

this message is sent to the trigger collider and the rigidbody (or the collider if there is no rigidbody) that touches the trigger. note that trigger events are only sent if one of the colliders also has a rigidbody attached.

這個消息是發送給觸發碰撞器和剛體(或如果沒有剛體的碰撞器)。注意如果其中一個碰撞器也附加了剛體,觸發事件才會發送。

note:ontriggerstay function is on the physics timer so it wont necessary run every frame.

注意:ontriggerstay函數是基于物理計時器,因此它未必每幀都運行。

也就是說ontriggerstay是在每一個time.fixeddeltatime的時間節點上運行,不是time.deltatime的時間節點上運行

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

void ontriggerstay(collider other) {

if (other.attachedrigidbody)

other.attachedrigidbody.addforce(vector3.up* 10);

}

}

// applies an upwards force to all rigidbodies that enter the trigger.

//進入觸發器給所有的剛體應用向上的力

function ontriggerstay (other : collider) {

if (other.attachedrigidbody) {

other.attachedrigidbody.addforce(vector3.up* 10);

}

}

相關閱讀

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