Reputation: 3
I am making a primarily 3D game, but with some 2D minigames. However, in one of these minigames, the player's OnCollisionEnter2D() is not detecting the collisions of any other object. My code is as follows:
public void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("CollisionOccurred");
if (collision.gameObject.tag == "PuzzleWall")
{
Debug.Log("Wall hit");
}
}
Unfortunately, despite being put through multiple objects on several occasions, neither Debug.Log() has triggered.
I have tried the following to fix the problem (to no avail):
Upvotes: 0
Views: 77
Reputation: 59
If your Collider2D components have IsTrigger enabled, then you need to use the function OnTriggerEnter2D()
rather than OnCollisionEnter2D()
. This is because when you have IsTrigger enabled, the collider does not behave like an actual collider, but rather a trigger.
Upvotes: 0