Getting Immersive with Sound FX
We have several places where we want to play sounds. Let’s see what sound clips we have first.
- Laser Sounds
- Explosion Sounds
- PowerUp Pickup Sounds
For the purpose of today’s article I’ll focus on the laser shot.
Assuming that you have your desired sound FX file chosen and imported into your assets folder in Unity.
On our Player in the hierarchy, select the player object and in the inspector. We’ll add an Audio Source component. Make sure to uncheck “Play On Awake”.
Then in our Player script we’ll create a variable for the AudioSource controller and a serialized field where we will drag our soundfile into from the asset folder to the inspector.
In our Player script in our start method we we’ll also check to make sure the Audio Source isn’t null.
Finally in our FireLaser() method we sinply call on the audioSource.play()