Unity 2D OnTriggerEnter Not Working, Tried Everything

Viewed 61

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. I have tried various combinations of dynamic and kinematic. Nothing happens.

1 Answers

Maybe you should try this one:

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