[英]Unity 2D OnTriggerEnter Not Working, Tried Everything
Ive been trying to find the solution to this for hours.几个小时以来,我一直试图找到解决方案。 I'm trying to learn but I've been stuck on this single problem.
我正在努力学习,但我一直被困在这个问题上。 I have red creatures that move around randomly, and I want them to clone themselves when they collide with the green objects.
我有随机移动的红色生物,我希望它们在与绿色物体碰撞时克隆自己。 Here is the script attached to the green objects.
这是附加到绿色对象的脚本。
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));
}
}
Both have 2D colliders, Rigidbody2Ds, the colliders are the right size, IsTrigger
is true on the food object.两者都有 2D 对撞机,Rigidbody2Ds,对撞机大小合适,
IsTrigger
在食物对象上为真。 I have tried various combinations of dynamic and kinematic.我尝试过动态和运动学的各种组合。 Nothing happens.
什么都没发生。
Maybe you should try this one:也许你应该试试这个:
public void OnTriggerEnter2D(Collider2D col)
{
// do something..
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.