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
collider2d
components - The entered object has a
rigidbody2d
component - The entered object's
collider2d
is set totrigger
- The entering object's
collider2d
is 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.