Hiero Match: Adding Exploding Particles Whenever Tiles Removed

Part 2 of the Hiero Match series: instantiate a particle explosion at each tile's position when a pair matches.

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 through chapter 3.

This post demonstrates how to incorporate an exploding effect into the game whenever tiles are removed.

Adding the Explosive Variable

First, add a new variable with GameObject type to the tileGenerator.js script:

//define variable explosiveObject with GameObject type
var explosiveObject : GameObject;

Note that explosiveObject initially remains empty (none), with assignment happening later.

Instantiating the Explosion Effect

The Instantiate() method creates the explosive particle effect object in the scene whenever tiles are destroyed. Place this code before destroying tile objects when a match occurs. In the revealCardTwo() function, insert the instantiation after confirming that Object1 and Object2 are paired but before destroying them:

function revealCardTwo(){
	//~~~ some code from Hiero Match > tileGenerator.js
		// check if Object 1 name and Object 2 name is same or paired
		if (tName1[0] == tName2[0]){
			// instantiate explosion effect using object1 position
			Instantiate(this.explosiveObject, matchOne.transform.position , Quaternion.identity);
			// instantiate explosion effect using object2 position
			Instantiate(this.explosiveObject, matchTwo.transform.position , Quaternion.identity);
			//destroy object 1 and object 2
			Destroy(matchOne);
			Destroy(matchTwo);
			//~~~ some code from Hiero Match > tileGenerator.js
		}
	//~~~ some code from Hiero Match > tileGenerator.js
}

Importing Standard Particles

  1. Navigate to Assets > Import Package > Particles
  2. In the import window, select desired particle effects (include materials, animations, and scripts) or import all
  3. Click the import button
  4. The Standard Assets folder with a Particles subfolder now appears in the Project View

Configuring the Particle Effect

Test each particle prefab by dragging it to the Hierarchy View and adjusting properties in the Inspector View. For this tutorial, the "small explosion" particle from Standard Assets > Particles > Legacy Particles is used.

Important configuration notes:

  • Check the Auto Destruct option under the Particle Animator section
  • Check the One Shot option under the Ellipsoid Particle Emitter

These settings ensure the effect plays once and automatically moves to garbage collection.

Assigning the Particle to the Script

  1. Apply changes to the prefab by selecting the particle in Hierarchy View
  2. Navigate to GameObjects > Apply Changes to Prefab
  3. Remove the particle from Hierarchy View (right-click > delete)
  4. Select the tileGenerator Object in Hierarchy View
  5. In Inspector View, change the Explosive Object variable to Small Explosion

Test the game with the play button — tiles now display an exploding effect whenever a match occurs.


This is part 2 of the Hiero Match series.