Collider.OnTriggerEnter 进入触发器


function OnTriggerEnter (other : Collider) : void

Description描述

OnTriggerEnter is called when the Collider other enters the trigger.

当碰撞器other进入触发器时OnTriggerEnter被调用。

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 OnTriggerEnter(Collider other) {Destroy(other.gameObject);}}
// Destroy everything that enters the trigger//当进入触发器销毁所有物体function OnTriggerEnter (other : Collider) {Destroy(other.gameObject);}


,