Unity5 OnTriggerEnter2D not called after collision (2D game)

I am a brand new to Unity3D 5 and am having problems with my first 2D game to include conflict detection. My moving object is a ball and has a Rigidbody2D and a CircleCollider2D. My stationary "collider or trigger" is BoxCollider and has a script. OnTriggerEnter2D should be triggered when the ball passes through a stationary box. I've also tried OnCollisionEnter2D, but I'm pretty sure I should be using OnTriggerEnter2D because my stationary box is marked as a trigger.

My code:

public class LoseCollider : MonoBehaviour {

public LevelManager levelManager;

void OnCollisionEnter2D(Collision2D collision)
{
    print("collide");
    levelManager.LoadLevel("Lose");
}

void OnTriggerEnter2D(Collider2D trigger)
{
    print("trigger");
    levelManager.LoadLevel("Lose");
}

void OnCollisionEnter(Collision collision)
{
    print("collide");
    levelManager.LoadLevel("Lose");
}

void OnTriggerEnter(Collider trigger)
{
    print("trigger");
    levelManager.LoadLevel("Lose");
}
}

      

As you can see, I am testing all options and no one gets called. Here are my Unity properties for my objects:

Ball

and

enter image description here

I'm sure I'm missing something simple if anyone can point me to this.

+3


source to share


1 answer


If you are going to use OnTriggerEnter2D

, you should also use 2D collider. You are currently using BoxCollider

as shown in the second screenshot.



Change this to BoxCollider2D

and call the Collision callback functions.

+4


source







All Articles