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

9.2 Adding Sound to Events

Sound effects tied to player actions and events make your game feel responsive and engaging.

Step 1: Footsteps

Create an array of footstep sounds and play them randomly when the player moves:

public AudioSource audioSource;
public AudioClip[] footstepSounds;

void PlayFootstep() {
    int index = Random.Range(0, footstepSounds.Length);
    audioSource.PlayOneShot(footstepSounds[index]);
}

Trigger this function during movement events (e.g., in the character controller script).

Step 2: Collisions

Use the OnCollisionEnter method to play sounds on impact:

void OnCollisionEnter(Collision collision) {
    if (collision.gameObject.CompareTag("Obstacle")) {
        audioSource.PlayOneShot(collisionSound);
    }
}
Step 3: Game Triggers

Add sound effects for specific game actions, like opening a door or collecting an item:

void OnTriggerEnter(Collider other) {
    if (other.CompareTag("Collectible")) {
        audioSource.PlayOneShot(collectibleSound);
    }
}

Activity: Implement footstep sounds and collision effects in a game scene.