0% found this document useful (0 votes)
74 views5 pages

Lesson Plan 3.4 - Particles and Sound Effects

Uploaded by

Agus Susanto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views5 pages

Lesson Plan 3.4 - Particles and Sound Effects

Uploaded by

Agus Susanto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

 
 
 

3.4​ P​ articles and Sound Effects 


 
Steps: 
Example of project by end of lesson 
Step 1: Customize an explosion particle 

Step 2: Play the particle on collision 

Step 3: Add a dirt splatter particle 

Step 4: Add music to the camera object 

Step 5: Declare variables for Audio Clips 

Step 6: Play Audio Clips on jump and crash 


 
 
 
Length:  60 minutes 

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. 

Learning  By the end of this lesson, you will be able to: 


Objectives:  - Attach particle effects as children to game objects 
- Stop and play particle effects to correspond with character animation 
states 
- Work with Audio Sources and Listeners to play background music 
- Add sound effects to add polish to your project 

   

© Unity 2019 Lesson 3.4​ - Particles and Sound Effects 



Step 1: Customize an explosion particle 
The first particle effect we should add is an explosion for when the player collides with an 
obstacle. 
1. From the C ​ ourse​ ​Library > Particles​, drag  - New Concept:​ Particle Effects  
FX_Explosion_Smoke​ into the hierarchy, then use  - Warning:​ Don’t go crazy customizing 
the ​Play​ / ​Restart​ / ​Stop​ buttons to preview it  your particle effects, you could easily 
get sidetracked 
2. Play around with the ​settings​ to get your ​particle 
- New Concept:​ Child objects with 
system​ the way you want it  relative positions 
3. Make sure to ​uncheck​ t​ he P ​ lay on Awake​ setting  - Tip:​ Hovering over the settings while 
4. Drag the ​particle​ onto your player to make it a  editing your particle provides great 
child object​, then position it relative to the player  tool tips 

 
 
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 

public​ ParticleSystem explosionParticle;

private​ ​void​ ​OnCollisionEnter​(Collision collision other) {


​if​ (other.gameObject.CompareTag(​"Ground"​)) {
isOnGround = ​true​;
} ​else​ ​if​ (other.gameObject.CompareTag(​"Obstacle"​)) {
... ​explosionParticle.Play();​ } }

© Unity 2019 Lesson 3.4​ - Particles and Sound Effects 



Step 3: Add a dirt splatter particle 
The next particle effect we need is a dirt splatter, to make it seem like the player is kicking up 
ground as they sprint through the scene. The trick is that the particle should only play when the 
player is on the ground. 
1. Drag F ​ X_DirtSplatter​ as the Player’s ​child object​, reposition  - New Function: 
it, rotate it, and edit its settings  particle.Stop()  
2. Declare a new p ​ ublic ParticleSystem dirtParticle;​, then 
assign​ it in the Inspector 
3. Add ​dirtParticle.Stop();​ when the player jumps or collides 
with an ​obstacle 
4. Add ​dirtParticle.Play();​ when the player lands on the ​ground 

public​ ParticleSystem dirtParticle

void​ U​ pdate​() {
​if​ (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver) {
... ​dirtParticle.Stop();​ } }

private​ ​void​ ​OnCollisionEnter​(Collision collision other) {


​if​ (other.gameObject.CompareTag(​"Ground"​)) { ... ​dirtParticle.Play();
} ​else​ ​if​ (other.gameObject.CompareTag(​"Obstacle"​)) { ... ​dirtParticle.Stop();​ } } 
 
Step 4: Add music to the camera object 
Our particle effects are looking good, so it’s time to move on to sounds! In order to add music, 
we need to attach sound component to the camera. After all, the camera is the eyes AND the 
ears of the scene. 
1. Select the Main ​Camera​ object, then A ​ dd  - New Concept:​ Audio Listener and 
Component > Audio Source  Audio Sources  
2. From ​Course Library > Sound​, drag a ​music clip  - Tip:​ Music shouldn’t appear to come 
from a particular location in 3D space, 
onto the ​AudioClip​ variable in the inspector 
which is why we’re adding it directly to 
3. Reduce the ​volume​ so it will be easier to hear  the camera 
sound effects 
4. Check the L​ oop​ checkbox 

   

© Unity 2019 Lesson 3.4​ - Particles and Sound Effects 



Step 5: Declare variables for Audio Clips 
Now that we’ve got some nice music playing, it’s time to add some sound effects. This time 
audio clips will emanate from the player, rather than the camera itself. 
1. In ​PlayerController.cs​, declare a new ​public  - Tip:​ Adding sound effects is not as 
AudioClip jumpSound;​ and a new ​public AudioClip  simple as adding music, because we 
crashSound;  need to trigger the events in our code 
2. From ​Course Library > Sound​, drag a clip onto each 
new ​sound​ variable in the inspector 

 
   

© Unity 2019 Lesson 3.4​ - Particles and Sound Effects 



Step 6: Play Audio Clips on jump and crash 
We’ve assigned audio clips to the jump and the crash in PlayerController. Now we need to play 
them at the right time, giving our game a full audio experience 
1. Add an ​Audio Source​ component to the p
​ layer  - Don’t worry:​ Declaring a new 
2. Declare a new ​private AudioSource playerAudio;  AudioSource variable is just like 
and initialize it as p
​ layerAudio =  declaring a new Animator or RigidBody 
GetComponent<AudioSource>(); 
3. Call ​playerAudio.PlayOneShot(jumpSound, 1.0f); 
when the character j​ umps 
4. Call ​playerAudio.PlayOneShot(crashSound, 1.0f); 
when the character c ​ rashes 

private​ AudioSource playerAudio;

void​ ​Start​() {
... ​playerAudio = GetComponent<AudioSource>();​ }

void​ U​ pdate​() {
​if​ (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver) {
... ​playerAudio.PlayOneShot(jumpSound, 1.0f);​ } }

private​ ​void​ ​OnCollisionEnter​(Collision collision other) {


...
} ​else​ ​if​ (other.gameObject.CompareTag(​"Obstacle"​))
{ ... ​playerAudio.PlayOneShot(crashSound, 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 

New Concepts  ● Particle systems  


and Skills  ● Child object positioning 
● Audio clips and Audio sources  
● Play and stop sound effects 
 
 

© Unity 2019 Lesson 3.4​ - Particles and Sound Effects 

You might also like