How to do it...

To animate particle system properties, follow these steps:

  1. Create an empty game object and name it AnimatedParticleSystem.
  2. Add a Particle System component to it.
  3. Create the particle system to your liking. We have a very simple particle system with particles flying in straight line in this example.
  4. Add an Animator component to the AnimatedParticleSystem game object.
  5. Create an animation of the EmissionRate parameter. It is only possible to directly animate Emission Module and Shape Module of a particle system.
  6. To animate other properties, create a new script and call it ParticleAnims.cs. In this script, we have two public variables: public float gravityModifier and public Color color. We use those variables to set the gravityModifier and the startColor properties of the particle system in the Update() function. The reference to the Particle System component is set in the Start() function and stored in the particles variable:
        void Update () { 
            particles.gravityModifier = gravityModifier; 
            particles.startColor = color; 
        } 
  1. Assign the script to the AnimatedParticleSystem game object.
  2. Open the Animation View again and animate the Color and Gravity Modifier public fields of the script. This way we can create a workaround to animate the particle system's properties unreachable from the Animation View.
  3. Play the game to see the effect.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.181.61