MonoBehaviour.OnTriggerEnter 当进入触发器

function OnTriggerEnter (other : Collider) : void

Description描述

OnTriggerEnter is called when the Collider other enters the trigger .

当Collider(碰撞体)进入trigger(触发器)时调用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 rigid body attached.

这个消息被发送到触发器碰撞体和刚体(或者碰撞体假设没有刚体)。注意如果碰撞体附加了一个刚体,也只发送触发器事件。

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

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

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

Page last updated: 2011-1-2