I am facing a problem with unity on a 2D project. OnTriggerEnter2D doesn't seem to be called as I have no prints on console.
Here is the script that calls the OnTriggerEnter2D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AbilityUnlock : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("Test");
if(other.tag == "Player")
{
Debug.Log("Player tag ");
Destroy(gameObject);
}
}
}
gameObject Collider
!
Project Collisions

RigidBody2D of the Player

Tag of the Player

The Script is attached to the gameObject.
Probably I am missing something that I can't see.Any help is very appreciated.
Thanks
CodePudding user response:
There are five things I always check when having trigger enter issues.
- Both objects are on physics layers that can interact with each other
- Both objects to have
collider2dcomponents - The entered object has a
rigidbody2dcomponent - The entered object's
collider2dis set totrigger - The entering object's
collider2dis not set totrigger
From your question it look like you've already got steps 1) and 4) looking good.
As other answers point out the most likely candidate is 3) - rigidbody2d not being on your entered object.
If none of that works, then you can try some more extreme measures such as setting the rigidbodys to never sleep or playing with the interpolation mode, but give that a go.
CodePudding user response:
You need Rigidbody2d Component on gameObject. Not only on player.
