Reputation: 77
There is a gameobject "collider" having a static collider
and a circle prefab having a dynamic rigidbody collider and a script destroyer attached to it
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
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
Reputation: 2943
It is OnCollisionEnter2D not OnCollisionEnter2d, case is important.
In addition, at least one of the two must have rigidbody attached.
Upvotes: 1