Unity 2D OnTriggerEnter不工作,尝试了所有方法



我花了好几个小时试图找到解决这个问题的方法。我在努力学习,但我被这个问题困住了。我有随机移动的红色生物,我希望它们在与绿色物体碰撞时克隆自己。下面是附在绿色对象上的脚本。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reproduction : MonoBehaviour
{
void OnTriggerEnter(Collider col) //Ive tried 'other' also, didnt make a difference
{
Destroy(col.gameObject);
Debug.Log("enter");
//GameObject a = Instantiate(other.GameObject) as GameObject;
//a.transform.position = new Vector2(Random.Range(-2f, 2f), Random.Range(-2f, 2f));
}
}

都有2D碰撞器,rigidbody2d,碰撞器的大小是正确的,IsTrigger在食物对象上是正确的。我尝试过各种动态和运动学的组合。什么也不会发生。

也许你应该试试这个:

public void OnTriggerEnter2D(Collider2D col)
{
// do something..
}

最新更新