MonoBehaviour.OnCollisionEnter2D(Collision2D)

Switch to Manual

Parameters

other 与该碰撞关联的 Collision2D 数据。

Description

当传入碰撞体与该对象的碰撞体接触时发送(仅限 2D 物理)。

Further information about the collision is reported in the Collision2D parameter passed during the call. If you don't need this information then you can declare OnCollisionEnter2D without the parameter.

注意:碰撞事件将发送到已禁用的 MonoBehaviours,以便允许启用 Behaviours,以响应碰撞。

另请参阅:Collision2D 类、OnCollisionExit2DOnCollisionStay2D

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Enemy") coll.gameObject.SendMessage("ApplyDamage", 10); } }