Collider.OnCollisionStay 逗留碰撞
function OnCollisionStay (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 the Collision class and not a Collider. The Collision class 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参数以避免不必要的计算。注意,如果碰撞器附加一个非动力学刚体,也仅发送碰撞事件。
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);
}
}