OnTriggerEnter 不起作用 [英] OnTriggerEnter not working
本文介绍了OnTriggerEnter 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public var enemy:GameObject;
enemy = GameObject.FindGameObjectWithTag("enemy");
function OnTriggerEnter(other:Collider)
{
if(other.gameObject.tag == "enemy")
{
Debug.Log("Dead");
Destroy(gameObject);
}
}
这个脚本附加到一个被实例化的预制箭头上.敌人有一个圆形碰撞器,箭头有一个盒子碰撞器.箭头已选中 IsTrigger.我做错了什么?两个游戏对象都附加了一个刚体 2D.
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 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文