MonoBehaviour.OnTriggerStay 当逗留触发器

function OnTriggerStay (other : Collider) : void

Description描述

OnTriggerStay is called once per frame for every Collider other that is touching the trigger .

当碰撞体接触触发器时,OnTriggerStay将在每一帧被调用。

This message is sent to the trigger and the collider that touches the trigger. Note that trigger events are only sent if one of the colliders also has a rigid body attached.

这个消息被发送到触发器和接触到这个触发器的碰撞体。注意如果碰撞体附加了一个刚体,也只发送触发器事件。

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);
}

OnTriggerStay can be a co-routine, simply use the yield statement in the function.

OnTriggerStay可以被用作协同程序,在函数中调用yield语句。

最后修改:2011年1月2日 Sunday 15:45

本脚本参考基于Unity 3.4.1f5

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