Module 1: Introduction to Game Development
Module 2: Unity Interface and Basics
Module 3: Introduction to C# Programming for Unity
Module 4: Physics and Movement
Module 5: 2D Game Development
Module 6: 3D Game Development
Module 7: User Interfaces and Game Mechanics
Module 8: Animation and Visual Effects
Module 9: Sound Design and Implementation
Module 10: Building and Deploying Your Game
Module 11: Advanced Topics and Next Steps

4.5 Collision Detection

Collisions allow objects to interact with one another. Let’s implement a simple collision detection system.

Step 1: Create a Collision Script
Attach the following script to your player object:

void OnCollisionEnter(Collision collision) {
    Debug.Log("Collided with: " + collision.gameObject.name);
}

Explanation:

  • OnCollisionEnter: Triggered when the object collides with another object.
  • collision.gameObject.name: Logs the name of the object it collided with.

Step 2: Test It

  1. Add another object (e.g., a wall) to your scene.
  2. Ensure both objects have Colliders.
  3. Press Play and observe the Console when the player collides with the object.