Collider.OnTriggerExit 退出触发器


function OnTriggerExit (other : Collider) : void

Description描述

OnTriggerExit is called when the Collider other has stopped touching the trigger.

当碰撞器other停止触动触发器时,OnTriggerExit被调用。也就是说,

当碰撞器离开触发器时,调用OnTriggerExit。

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.

这个消息是发送给触发碰撞器和刚体(或如果没有刚体的碰撞器)。注意如果其中一个碰撞器也附加了刚体,触发事件才会发送。

  • C#

  • JavaScript

using UnityEngine;using System.Collections;public class example : MonoBehaviour {    void OnTriggerExit(Collider other) {    Destroy(other.gameObject);    }}
// Destroy everything that leaves the trigger//离开触发器时,销毁所有物体function OnTriggerExit (other : Collider) {Destroy(other.gameObject);}


,