![]() |
VOOZH | about |
Collision detection is the system that tells you when two GameObjects touch each other. When a collision happens, Unity automatically calls special methods in your scripts, allowing you to respond like reducing health, playing a sound, or destroying an object.
Unity provides three collision events that you can use in your scripts:
Example
It gives you useful information about the impact:
For OnCollisionEnter/Stay/Exit to work:
Not working? Check these:
Example 1: Player takes damage when hitting enemy
Example 2: Bullet destroys on impact
Example 3: Play sound based on impact speed
| Feature | Collision | Trigger |
|---|---|---|
| Method to Use | OnCollisionEnter() | OnTriggerEnter() |
| Physical Interaction | Objects physically collide (block each other) | Objects do not block (only overlap detection) |
| Is Trigger Option | Not checked | Must be checked |
| Use Case | Solid objects (walls, floors, enemies) | Detection only (coins, checkpoints, pickups) |