For Project 1, I created a particle effect that changes based on whether the player has finished the level or not. The purpose of this particle effect is to have a more visually appealing indicator that the level is complete and that the player can move to the next one. I also wanted the particle effect to match the art style of the game, which is pixel graphics. Note that this project was done in 2D.
I started by creating a Particle System in Unity by right-clicking inside the Hierarchy and selecting the Particle System option.
Doing this will make a GameObject called Particle System appear, similar to the Particle System that, as you can see, is a child of the ExitLevel GameObject.
The default Particle System shoots white circles in a cone shape, as can be seen below. However, this doesn’t fit well with the current theme of the game.
So, to fix this, the first thing I did was to change the Material in the Renderer settings. I want this particle effect to mimic a section of the border so I created a Material that is the same colour as the border and applied it to the Particle System, the result of which you can see below. Note, however, that in order to get this result I had to change the Shader that is on the Material from Standard to Unlit > Color.
The next thing that I changed was the Shape. The default shape is a cone but, in order to make a believable-looking wall, that will have to change. After experimenting with a few different shapes, I settled on the Edge shape.
The first thing to adjust is the rotation. The default X rotation of a Particle System is -90 degrees which means that, with the Edge Shape applied, the particles are now shooting towards the camera, if in the 2D camera setting. Set the X rotation to 0 to stop that. So now the Particle System should look the the one pictured below.
Now, while that seems all well and good, it doesn’t mimic a wall very well. The first step to fixing this is to position the Particle System where I want it and adjust its value from there. As you can see in the picture below it doesn’t fit quite, since it is supposed to fit in the small opening in the border below it.
The first setting I change was the Start Size, to 0.1, since those particles are far too large for what I need them to do. Then I went to Shape > Radius and changed it to 1.8 in order stop the particles from extending into the border. After that I did some tinkering with both Start Lifetime and Start Speed, finally settling on 1 and 0.66 respectively.
The Particle System now looks like the image below. There is a fairly obvious problem here, that problem being that there aren’t nearly enough particles to make a convincing mimic of a wall.
In order to add more particles, I went to Emission > Rate Over Time and changed it to 10,000. This, however, isn’t the only setting that must change. If you don’t change Max Particles to 10,000 (Rate over Time multiplied by Start Lifetime) as well, you will get a solid line of particles once every second instead of a block of particles.
The image below is a big block of 10,000 particles. Now, all that remains is adding some functionality through coding.
Here is what I have written for the Particle System:
The first thing I do is reference the EndLevel script because there is a function in there that detects if all the enemies have been defeated. Then I wrote a public reference to the Particle System. This allows me to assign the Particle System in the Inspector. Finally, the float partiChange determines the rate at which the Particle System decreases emission.
The function LevelComplete() check if all the enemies are defeated and, if so, retrieves the emission and then the emission.rate of the Particle System. I then change the constantMax of the emission.rate so that it decreases according partiChange. Then, last of all, is an if statement that checks if the constantMax goes below a certain point. If it does go below that amount the rate that constantMax decreases at is set to 0, meaning that it remains at the rate that it dropped to.
This script is then attached to the ExitLevel object that was in the Hierarchy from earlier. Now the Particle System is done and this is the final result.