Lesson Plan 3.4 - Particles and Sound Effects
Lesson Plan 3.4 - Particles and Sound Effects
Overview: This game is looking extremely good, but it’s missing something critical:
Sound effects and Particle effects! Sounds and music will breathe life into an
otherwise silent game world, and particles will make the player’s actions
more dynamic and eye-popping. In this lesson, we will add cool sounds and
particles when the character is running, jumping, and crashing.
Project Music will play as the player runs through the scene, kicking up dirt particles
Outcome: in a spray behind their feet. A springy sound will play as they jump and a
boom will play as they crash, bursting in a cloud of smoke particles as they
fall over.
Step 2: Play the particle on collision
We discovered the particle effects and found an explosion for the crash, but we need to assign
it to the Player Controller and write some new code in order to play it.
1. In PlayerController.cs, declare a new public ParticleSystem - New Function:
explosionParticle; particle.Play()
2. In the Inspector, assign the e xplosion to the e
xplosion particle variable
3. In the if-statement where the player collides with an obstacle, call
explosionParticle.Play();, then test and tweak the p article properties
void U pdate() {
if (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver) {
... dirtParticle.Stop(); } }
void Start() {
... playerAudio = GetComponent<AudioSource>(); }
void U pdate() {
if (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver) {
... playerAudio.PlayOneShot(jumpSound, 1.0f); } }
Lesson Recap
New ● Music plays during the game
Functionality ● Particle effects at the player’s feet when they run
● Sound effects and explosion when the player hits an obstacle