Mohammad AL - Haque
Mohammad AL - Haque

Reputation: 77

two colliders are colliding but then also OnColliderEnter2d function is not getting executed

There is a gameobject "collider" having a static collider

enter image description here

and a circle prefab having a dynamic rigidbody collider and a script destroyer attached to it

enter image description here

the script is

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class destroyer : MonoBehaviour
{
   private void OnCollisionEnter2d(Collision2D collision)
    {
        Destroy(gameObject);
        print("3");
    }
}

on running the game the circle prefab which is instantiated is colliding with the static collider but the OnCollisionEnter2d function is never getting called enter image description here

first I thought that Destroy is not working but then I use print function and nothing is printed in console and then I get to know that OnCollisionEnter2d is never called

Upvotes: 1

Views: 205

Answers (1)

Yuri Nudelman
Yuri Nudelman

Reputation: 2943

It is OnCollisionEnter2D not OnCollisionEnter2d, case is important.

In addition, at least one of the two must have rigidbody attached.

Upvotes: 1

Related Questions