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);
	}
}
最后修改:2010年12月12日 Sunday 16:00

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。