Collider.OnTriggerStay 逗留触发器

function OnTriggerStay (other : Collider) : void

Description描述

OnTriggerStay is called almost all the frames for every Collider other that 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的时间节点上运行

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);
	}
}
Page last updated: 2013-7-12