本文介绍了OnTriggerEnter不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public var enemy:GameObject;
enemy = GameObject.FindGameObjectWithTag("enemy");
function OnTriggerEnter(other:Collider)
{
if(other.gameObject.tag == "enemy")
{
Debug.Log("Dead");
Destroy(gameObject);
}
}
此脚本附加到实例化的预制箭头上。敌人有一个圆形对撞机,箭头有一个盒子对撞机。 IsTrigger上的箭头已选中。我做错了什么?
This script is attached to a prefab arrow that gets instantiated. The enemy has a circle collider and the arrow has a box collider. The arrow has on IsTrigger checked. What have I done wrong? Both gameobjects have a rigidbobdy2D attached.
推荐答案
如果使用2D物理引擎,则需要使用2D函数:
If you use the 2D physics engine, you need to use the 2D functions:
function OnTriggerEnter2D(other: Collider2D)
{
if(other.tag == "enemy")
{
Debug.Log("Dead");
Destroy(gameObject);
}
}
这篇关于OnTriggerEnter不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!