Hiero Match: Polish Your Game a Little Bit 'Shine'

Part 6 of the Hiero Match series: persistent background music with a singleton, sound effects for every event, and a time-based score.

Hiero Match is a matching/pairing game tutorial using Unity3D from the book Unity 3 Blueprints, written by Craig Stevenson and Simon Quig, and published by Deep Pixel. This tutorial spans from chapter 2 to chapter 3.

This post demonstrates how to enhance your game's polish by adding music and sound effects. Music has been an essential part of games for decades — sound design helps players emotionally connect with gameplay experiences.

1. Playing Music on the Entire Game

The challenge with multiple scenes is that game objects get destroyed during scene transitions. The solution uses a singleton pattern to keep audio persistent across scenes.

using UnityEngine;
using System.Collections;

public class myUnitySingleton : MonoBehaviour {

	private static myUnitySingleton instance = null;
	public static myUnitySingleton Instance {
		get { return instance; }
	}
	// Use this for initialization
	void Start () {

	}
	// Update is called once per frame
	void Update () {

	}

	void Awake() {
		if (instance != null && instance != this) {
			Destroy(this.gameObject);
			return;
		} else {
			instance = this;
		}
		DontDestroyOnLoad(this.gameObject);
	}
	// any other methods you need
}

Attach this script only to the first scene (menu scene). Enable "Play on awake" and "Loop" options on the audio source component.

2. Playing Sound Effects

Add an Audio Source component to the tileGenerator GameObject. Define audio clip variables in the script:

//define our soundClip
var soundTileSliding : AudioClip;
var soundBooing : AudioClip;
var soundCheers : AudioClip;
var soundTicking : AudioClip;
// we need to define isPlayed variable to state if Booing or Cheering is already played
// because we will call this sfx on Unity3D Update() function, which is looped through game time
var isPlayed = false;

a. Booing and Cheers Sound

Play these when the game finishes:

if (this.isPlayed == false){
	if (finished == true){
		//play cheering sound
		audio.PlayOneShot(this.soundCheers,0.5f);
		isPlayed = true;
	}

	if (timeUp == true) {
		//play booing sound
		audio.PlayOneShot(this.soundBooing,0.8f);
		isPlayed = true;
	}
}

b. Ticking Sound

Play this when the timer speeds up:

//play ticking sound
audio.PlayOneShot(this.soundTicking,1.0f);

c. Sliding Tile Sound

Play this when tiles slide:

audio.PlayOneShot(this.soundTileSliding,1.0f);

3. Rig the Scoring Mechanism

Implement scoring that rewards faster completion times:

//score added
scoreInt = scoreInt + (1+(roundedSeconds/10));

Create custom scoring rules to match your specific game design needs.


This is part 6 of the Hiero Match series.