Immersion Starts with Sound

Day 25 — Aspiring Game Creator

2D Game Dev: Galaxy Shooter

Galaxy Shooter with very descriptive sounds!

Objective: Add background audio to Galaxy Shooter.

Pseudo Code or actually, the needed components:

  • Audio Listener — component which “plays” all the audio through the laptop/computer’s audio device: laptop speaker, headphone, HDMI attached speaker. This component is usually attached to the Main Camera.
  • Audio Source — component attached to a game object which will play the sound for that game object, though it’s actually piping that sound to the audio listener.
  • Audio Clip — this is THE actual audio file.

Background music in three easy steps:

  1. Not much to this step, but important to check. The Main Camera game object has the required AUDIO LISTENER. If not, add the component.
  2. Create an empty game object: AudioManager, then a child object BackgroundMusic.
  3. Drop the BackgroundMusic track onto the BackgroundMusic game object. Ensure both Play On Awake and Loop are enabled, maybe turn the volume down a bit.

Dropping the music file directly onto the game object automatically adds the necessary Audio Source component and sets the Audio Clip too.

LET THERE BE SOUND! (just click play)

This is the absolute rudimentary, but workable way to get sound into the game, but there is another solution: Unity’s Audio Mixer which will be discussed in Day 26th’s article: How to Play Sound Effects in Unity.

Aspiring Game Creator