Are you having a little trouble believing that the process of dismembering characters is so clean? Normally, beheading makes a big mess — this game should be no exception. You’ll use particles to increase the, um, realism a bit.
Particles are small bits of geometry created by a game engine that you can use to create effects such as fire, water and other chaotic systems.
Ever play a game that featured snow? In most cases, the effect was produced by a particle emitter directly over the character. It probably seemed like it was snowing in the entire game world, but the particle emitter was most likely following you around like a little dark cloud.
Particles are a deep topic that you should cover in more depth on your own. For convenience, in this tutorial, you’ll use pre-made particles.
Note: This tutorial is part of a collection that teaches Unity development from the ground up. You can read the entire series over here. This series is free and does not require any account creation. All assets are provided. If you find it useful, feel free to buy me a coffee.
Adding some alien blood
In the Project window, drag an instance of the AlienDeathParticles prefab into the scene. You’ll see an instant splash of alien blood. Ew!

Select it in the Hierarchy. In the upper right hand corner of the Scene view, you’ll see a particles button. This provides some details about your particles.

This control panel lets you tweak settings in real time when building particle effects. Press the Play button. You’ll see the blood fly once again and notice that the button becomes a Pause button. You also have a Stop button to end the particle effect.
Temporarily drag an Alien prefab into the scene, and, in the Hierarchy, drag AlienDeathParticles to make it a child of Alien. With AlienDeathParticles selected, set Position to (0, 1.07, -1.7) and Rotation to (-90, 0, 0). Click the Apply button to apply the changes to the AlienDeathParticle prefab.

They’re working, but they fall through the floor, so clearly you need special treatment for the particles. You could have the particles collide with the world but, in this case, a death floor makes more sense.
Creating a death floor
In the Hierarchy, select BobbleArena. Click the Create button, select 3D Object and choose Plane. Name it DeathFloor and drag it to be a child of BobbleArena. Set Position to (8.66, -0.16, 12.15) and Scale to (-14.9, 0.5, 15.6). Uncheck the Mesh Collider and Mesh Renderer to disable them.
In the Hierarchy, select AlienDeathParticles. You’ll see there are many options for particles.

Expand the Collision section by clicking on it — scroll down if you don’t see it. Drag the DeathFloor to the Planes property.

The blood could be better. In the AlienDeathParticles. Set the Gravity Modifier to 3.

Click the Play button. The blood will pool on the new floor!
Sorting the blood
Now you have to address a small rendering issue. In this case, Unity renders the particles underneath the floor because it draws the floor after it draws the particles.
To avoid this, you need to assign the particles to a Sorting Layer, which will determine the order in which Unity renders objects. Typically, you use these with Unity 2D, but there are use cases for sorting layers in 3D games, too.
Expand the Renderer section of the particle system. In the Sorting Layer ID property, select Add Sorting Layer…. The Inspector will change to Tags & Layers. Click the + and name the sorting layer Foreground.
Return to the Renderer module, and in the Sorting Layer ID, select the Foreground property. Keep in mind that you’ll need to do the same thing for the space marine.

Expand the Renderer section of the particle system. In the Sorting Layer property, select Add Sorting Layer…. The Inspector will change to Tags & Layers. Click the + and name the sorting layer Foreground.

Return to the Renderer module, and in the Sorting Layer, select the Foreground property. Keep in mind that you’ll need to do the same thing for the space marine.
Now click the Apply on your Alien to apply all your changes to the Prefab. You’ve unveiled a new problem: The death floor isn’t added to the prefab because it’s an instance in the scene and your Alien prefabs don’t know about it. You’ll address this in a moment.
Updating the marine
Meanwhile, give your hero some blood, too. Drag the MarineDeathParticles prefab to be a child of the BobbleMarine-Body. Set Position to (-1.68, 5.29, 0.63) and Rotation to (-90, 0, 0).
In the Particle System component, set the Gravity Modifier to 0.5. This provides a fountain spray. Expand the Collision section and drag the DeathFloor to the Planes property. In the Renderer section, set the Sorting Layer ID to Foreground.
Click the Play button to see the marine gush like a fountain.

The particle systems are ready to go for the aliens and space marine; you just need to activate them in code.
Accessing particles in code
Unity allows for all sorts of adjustments to particle systems in code. In your case, you just need to know if the particle system is running or not.
In the Project window, select the Scripts folder and click the Create button. Choose C# Script and name it DeathParticles. Open the script in your editor.
Add the following instance variables:
private ParticleSystem deathParticles;
private bool didStart = false;
deathParticles
refers to the current particle system and didStart
lets you know the particle system has started to play.
You need to get a reference to the particle system, so add the following to Start()
:
deathParticles = GetComponent<ParticleSystem>();
Add the following method:
public void Activate()
{
didStart = true;
deathParticles.Play();
}
This starts the particle system and informs the script that it started. In Update()
, add the following:
if (didStart && deathParticles.isStopped)
{
Destroy(gameObject);
}
Once the particle system stops playing, the script deletes the death particles because they are meant to play only once.
Finally, to address the need for a collision plane set in code, add the following method:
public void SetDeathFloor(GameObject deathFloor)
{
if (deathParticles == null)
{
deathParticles = GetComponent<ParticleSystem>();
}
deathParticles.collision.SetPlane(0, deathFloor.transform);
}
The script first checks to see if a particle system has been loaded, which is necessary because the Alien prefab is instanced and used immediately.
In case Start()
hasn’t been called and deathParticles
isn’t populated, this line populates it. Then it sets the collision plane.
Activating the particles
Now to activate the particles — it’s a similar process for the aliens and the marine, but the aliens require a little set-up work.
First, you need to get a reference to the particle system and it’s a child of the Alien GameObject, so you need code to get it.
Open Alien in your code editor, and add the following instance variable:
private DeathParticles deathParticles;
Then create the following method:
public DeathParticles GetDeathParticles()
{
if (deathParticles == null)
{
deathParticles = GetComponentInChildren<DeathParticles>();
}
return deathParticles;
}
The magic occurs in GetComponentInChildren()
. It returns the first death particle script that it finds. There’s only one script so there’s no possibility of grabbing the wrong one.
In Die()
, add the following before Destroy(gameObject)
:
if (deathParticles)
{
deathParticles.transform.parent = null;
deathParticles.Activate();
}
This makes the blood splatter when an alien dies. You have to remove the parent. Otherwise, the particles are destroyed along with the GameObject.
Open GameManager and add this instance variable:
[SerializeField]
private GameObject deathFloor;
This contains a reference to the death floor.
Add the following after alienScript.OnDestroy.AddListener(AlienDestroyed);
in Update()
:
alienScript.GetDeathParticles().SetDeathFloor(deathFloor);
Finally, save all your files and switch to Unity.
Final settings
In the Project view, expand the Alien prefab and select the AlienDeathParticles GameObject. Click Add Component and, under scripts, choose DeathParticles.
Next, select the GameManager in the Hierarchy and drag the DeathFloor to the DeathFloor property in the Inspector.
Delete the Alien from the hierarchy as that was only a temporary copy and you don’t need it anymore.
Now play your game and shoot some aliens — you might need a mop.

Now, for the marine. Select MarineDeathParticles in the Hierarchy and click Add Component. Under scripts, choose DeathParticles. Next, open the PlayerController in your editor. Add the following instance variable:
private DeathParticles deathParticles;
In Start()
, add the following:
deathParticles = gameObject.GetComponentInChildren<DeathParticles>();
Finally, in Die()
, add the following before Destroy()
:
deathParticles.Activate();
Play your game and charge those aliens. You’ll get a satisfying splatter when the marine dies.

Congratulations! You’ve lost the game!
Where to go from here
Nice work! Particle systems can really make a game pop. You can use them for all sorts of effects in your game. They add a lot of graphical pop to your game. As you saw, particle systems also contain numerous options. Play around with them and see what kind of effects you can add to the game.
As is, there’s only one last thing to do. You need to create a way to win the game and you’ll do that in the next and final tutorial.
Discover more from Jezner Books
Subscribe to get the latest posts sent to your email.