Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Controlling ParticleSystem time manually

Discussion in 'Scripting' started by User340, Dec 20, 2014.

  1. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Is there any way to control the time of a ParticleSystem through code? Just exactly like you can do it in the editor scene view. I for the life of me can't find a way to mimic that behavior at runtime. Unfortunately I have a suspicion that unity hasn't exposed enough of it's API :(. This is the best I have come up with:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(ParticleSystem))]
    4. public class ParticleSystemSampler : MonoBehaviour
    5. {
    6.    public float playbackTime = 0f;
    7.  
    8.    void Awake()
    9.    {
    10.       particleSystem.randomSeed = 1;
    11.    }
    12.    void Update()
    13.    {
    14.       particleSystem.Simulate(playbackTime, true, true);
    15.    }
    16. }
    17.  
    It works great up until playbackTime surpasses the ParticleSystem's startLifetime variable. At that point playbackTime becomes ineffective.

    Screen Shot 2014-12-19 at 9.11.11 PM.png
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001