找回密碼
 注冊帳號

掃一掃,訪問微社區

collider.oncollisionstay 逗留碰撞

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

摘要: collider.oncollisionstay 逗留碰撞functiononcollisionstay(collisioninfo: collision) : voiddescription描述oncollisionstay is called once per frame for every collider/rigidbody that is touching rigidbody ...

collider.oncollisionstay 逗留碰撞

functiononcollisionstay(collisioninfo: collision) : void

description描述

oncollisionstay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.

每個collider/rigidbody觸動rigidbody/collider,將在每幀調用oncollisionstay。通俗的說,

一個碰撞器或剛體觸動另一個剛體或碰撞器,在每幀都會調用oncollisionstay,直到它們之間離開不接觸。

in contrast to ontriggerstay, oncollisionstay is passed thecollisionclass and not a collider. thecollisionclass contains information about contact points, impact velocity etc. if you don't use collisioninfo in the function, leave out the collisioninfo parameter as this avoids unneccessary calculations. note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.

相比ontriggerstay,oncollisionstay傳遞collision類而不是collider。collision類包含接觸點,碰撞速度等信息。在這個函數如果你不使用collisioninfo,刪去collisioninfo參數以避免不必要的計算。注意,當其中至少一個碰撞盒附加非動力學剛體時碰撞事件才會發送。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

void oncollisionstay(collision collisioninfo) {

foreach (contactpoint contact in collisioninfo.contacts) {

debug.drawray(contact.point, contact.normal * 10, color.white);

}

}

}

function oncollisionstay(collisioninfo : collision) {

// debug-draw all contact points and normals

//調試繪制全部接觸點和法線

for (var contact : contactpoint in collisioninfo.contacts) {

debug.drawray(contact.point, contact.normal * 10, color.white);

}

}

相關閱讀

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