2
    private void OnTriggerEnter2D(Collider2D collider)
    {
        Debug.Log(collider.gameObject.tag);
    }

When it collides with the weapon (or anything) it should print the tag. The problem is that it doesn't print anything. enter image description here

Here you can see the player (normal colours) hitting the AI (green) and I am 100% that the AI is within the bounds of the weapons hitbox.

enter image description here

The AI layer and the player layers do interact with each other. enter image description here

This is the box collider on the weapon (ignore it being disabled)

enter image description here

This is the box collider on the AI. I have tried using ontriggerenter2D, ontriggerstay2D, ontriggerexit2D, ontriggerenter, ontriggerstay, ontriggerexit, oncollisionexit, oncollisionstay. I honestly have no clue why it is like this.

I know that it is not entering the on collision enter because it should be printing the ground tag that I have on the ground. Also the game is in 2D.

Arya Akhavein
  • 343
  • 1
  • 7

2 Answers2

1

I believe the rigidbody or the collider have to be on the same game object as the script for the collision/trigger enter and exit methods to be called.

22pool
  • 38
  • 6
0

Please check the following:

  • The OnTriggerEnter2D(Collider2D collider) is on a script that inherits from MonoBehaviour
  • This same MonoBehaviour script is in one of the GameObjects (Player or AI)
  • This script is attached to a GameObject that also has a Collider2D component

Last but not least...

Milena
  • 97
  • 2
  • 10