How do I use trigger colliders in Unity?

I am trying to create a “Fruit Ninja” style game in Unity in VR. I have a BoxCollider on my sword set to “Trigger” and I have some “fruit” objects coming towards it. I then have this function:

void OnTriggerEnter(Collider other) {     Destroy(gameObject);     Destroy(other.gameObject); } 

I’ve tried applying this script to the sword and to the objects, but nothing is destroyed.

In the documentation, there is also a note of “Trigger events are only sent if one of the Colliders also has a Rigidbody attached”, but I’ve attached a Rigidbody to the objects.

Unity Colliders – How do I detect nearby objects without my detection ranges detecting each other

How can I get both colliders’ types in a trigger overlap message like OnTriggerExit2D(Collider2D other)?


  • objects A and B both have a BoxCollider2D and CircleCollider2D components.

  • Then, object A enters one of the trigger colliders of object B.

  • I can get object B‘s collider type with the is operator.

How can I get A’s collider type?

The reason I want this is that I want only collisions where object A‘s CircleCollider2D touches object B‘s BoxCollider2D.

void OnTriggerExit2D(Collider2D other) {     if (other is BoxCollider2D)         //Do Code } 

Here is a table of what I want: I want only to register trigger overlaps from CircleCollider2D to BoxCollider2D. With the is operator, I can safely remove all collisions to CircleCollider2D but collisions between two BoxCollider2D stay, which I do not want.

+------------------+---------------+------------------+ |  Row to Column   | BoxCollider2D | CircleCollider2D |  +------------------+---------------+------------------+ | BoxCollider2D    | No            | No               |  | CircleCollider2D | Yes           | No               |  +------------------+---------------+------------------+ 

Edit The real questions was to detect nearby objects without the detection range dectecting each other.

How to fix model with colliders ignoring physics/collision

enter image description hereProblem: Imported model with Rigidbody and (later added) capsule collider ignores physics and collision with terrain, while other models with colliders work as intended.

Summary: I’m working with the robot kyle model/rigging free asset from the unity asset store. I added an animator controller with idle, walk, run, and jump animations and a simple script for movement. No custom physics scripts attached. I have a ball in the scene with a sphere collider and it works as intended with terrain collision and gravity and projectile motion.