UPDATE: Make sure to double check that both the laser and enemy prefabs have both Rigidbody 2D and Box collider 2D components! I forgot to add the box collider2D to my lasers so they didn’t register as a colldier
Silly me!
Hey everyone. I’m having a hard time with detecting the laser collisions with the enemies. My code is pretty much exactly the same as demonstrated in the video:
void OnTriggerEnter2D(Collider2D collider)
{
Projectile laser = collider.gameObject.GetComponent<Projectile>();
if (laser)
{
Debug.Log("Collided with projectile");
}
}
But when I run the game and shoot the enemies, the console doesn’t print anything.
I already checked to make sure both the enemy prefab and the laser prefab have RigidBody2D components.
Enemy has a Box Collider 2d Component and Is Trigger is checked.
Enemies and lasers are on the same Z plane.
I’ve restarted Unity several times.
Not really sure what else to check for at this point.
