How to Create a Particle Effect Via Script in Unity

Save

Particle effects are used to create smoke, water, fire and other elements in movie special effects and graphic engines. Unity is a program for creating such particles. Creating a particle effect in Unity scripts involves creating a particle emitter, particle animator and particle renderer. Without all three, the particle effect will not work. Particle emitters work with particle animators and renderers to create, manipulate and display particle systems correctly. 

Mesh Particle Emitter

  • Open the Mesh Particle Emitter Inspector. Under "Ellipsoid Particle Emitter," enable "Emit" to make the emitter emit particles. Specify the "Min Size" and "Max Size" each particle can be at a time when spawned. Configure the "Min Energy" and "Max Energy" for the lifetime of the particle in seconds. 

  • Specify the "Min Emission" and "Max Emission" for spawning particles per second. Input your values for "World Velocity" and "Local Velocity" to dictate the starting speed of particles in the world space along X, Y and Z. The "Rnd Velocity" adds a random velocity speed along X, Y and Z. "Tangent Velocity" specifies the starting speed of particles across the Emitter's surface along X, Y and Z. 

  • Enable "Simulate In World Space" to stop particles when the emitter moves. Enable "One Shot" if you want the particle numbers specified by minimum and maximum emission to spawn simultaneously. If "Interpolate Triangles" is true, then particles spawn all over the mesh's surface. 

  • Enable "Systematic" to spawn particles in the order of the vertices as defined in the mesh. Specify the "Min Normal Velocity" and "Max Normal Velocity" to dictate the amount of particles thrown away from the mesh. 

Particle Animator

  • Open the Particle Animator Inspector. Enable "Does Animate Color" to cycle particle color. Specify the "Color Animation" to determine the five colors that particles cycle through. Use "World Rotation Axis" as an optional attribute for a world-space axis the particles can rotate around. This can be used for advanced spell effects, among other advanced particles.

  • Configure the "Local Rotation Axis" as an option for rotating particles around a local-space axis for advanced spell effects or bubbles. Use "Size Grow" to make particles grow over their lifetime. This effect can simulate smoke rising or wind. Specify "Rnd Force" to add a random force to particles in each frame (a way of giving "life" to smoke effects.) 

  • Input values for "Force" to apply a certain amount of force to the particles each frame. Specify how much particles slow down in each frame using values for "Damping." For instance, the value of 1 will give no damping, while a negative value will slow particles down. 

  • Enable "Autodestruct" to destroy a "GameObject" attached to the Particle Animator once all particles disappear. 

Particle Renderer

  • Open the "Standard Assets," "Particles" and "Sources" folders to find pre-made materials.  

  • Create a new material by navigating to "Select Assets," "Create Other" and "Material" from the menu bar. Choose one of the shaders from the shader popup in the Particles group, such as "Particles" and "Multiply." 

  • Adjust the "Camera Velocity Scale" to determine the amount of stretching to apply to the particles based on camera movement. Use "Stretch Particles" to determine how the particles are rendered. Use "SortedBillboard" as an option to sort the particles by depth. 

  • Enable "Stretched" to make the particles face the direction they are moving in. Align particles flat along the X and Z axes using "VerticalBillboard." Align particles flat along the X/Y axes using "HorizontalBillboard." Set "Length Scale" if "Stretched Particles" is set to "Stretched" to specify how long particles remain in their motion direction. 

  • Adjust the "Velocity Scale" if "Stretch Particles" is set to "Stretched" to determine the particles' rate of stretching based on their speed. Enable "UV Animation" to generate the UV coordinates of the particles with a tile animated texture. To use the animated tile feature, make a texture from a grid of images. This adds life to particles or can make debris pieces rotate. Specify "X Tile" and "Y Tile" to determine the number of frames across the X and Y Axes respectively. Use "Cycles" to specify the amount of loops in the animation sequence. 

Related Searches

References

  • Photo Credit Hemera Technologies/AbleStock.com/Getty Images
Promoted By Zergnet

Comments

Related Searches

Check It Out

12 Tiki Essentials to Turn Your Bar Cart Into a Tropical Paradise

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!