Lesson 3.4 - Particles and Sound Effects
Customize an explosion particle
- From the Course Library > Particles, drag FX_Explosion_Smoke into the hierarchy, then use the Play / Restart / Stop buttons to preview it
- Play around with the settings to get your particle system the way you want it
- Make sure to uncheck the Play on Awake setting
- Drag the particle onto your player to make it a child object, then position it relative to the player
Play the particle on collision
- In PlayerController.cs, declare a new public ParticleSystem explosionParticle;
- In the Inspector, assign the explosion to the explosion particle variable
- In the if-statement where the player collides with an obstacle, call explosionParticle.Play();, then test and tweak the particle properties
Add a dirt splatter particle
- Drag FX_DirtSplatter as the Player’s child object, reposition it, rotate it, and edit its settings
- Declare a new public ParticleSystem dirtParticle;, then assign it in the Inspector
- Add dirtParticle.Stop(); when the player jumps or collides with an obstacle
- Add dirtParticle.Play(); when the player lands on the ground
Add music to the camera object
- Select the Main Camera object, then Add Component > Audio Source
- From Course Library > Sound, drag a music clip onto the AudioClip variable in the inspector
- Reduce the volume so it will be easier to hear sound effects
- Check the Loop checkbox
Declare variables for Audio Clips
- In PlayerController.cs, declare a new public AudioClip jumpSound; and a new public AudioClip crashSound;
- From Course Library > Sound, drag a clip onto each new sound variable in the inspector
Play Audio Clips on jump and crash
- Add an Audio Source component to the player
- Declare a new private AudioSource playerAudio; and initialize it as playerAudio = GetComponent<AudioSource>();
- Call playerAudio.PlayOneShot(jumpSound, 1.0f); when the character jumps
- Call playerAudio.PlayOneShot(crashSound, 1.0f); when the character crashes