I have some particle systems parented to a rigged character, with several animations on the character. At certain points during the animation, I want to play one of the particle systems, then have it stop, and play again later in the animation.
The situation is - I cannot animate ParticleSystem.enableEmission on that object (for an unrelated reason), so I have made a script that accepts a public ParticleSystem, and when the GameObject holding the script is enabled, it calls ParticleSystem.Play(). Like so:
using UnityEngine;
using System.Collections;
public class ParticleAniCtrl : MonoBehaviour {
public ParticleSystem particle;
void OnEnable() {
if(particle) {
if (!particle.isPlaying) {
particle.Play();
}
}
}
void OnDisable() {
if(particle) {
if (particle.isPlaying) {
particle.Stop();
}
}
}
}
(Play on awake is unchecked on the systems I’m using.)
This actually works fine. But this project is going to be sent off to another studio and I am concerned that they are going to ask me to do these animations without adding any new script that isn’t in their system already.
I thought of leaving PlayOnAwake checked in the particle system, and simply animating whether the particle system is enabled. The problem is, this doesn’t always work if it’s not the first playthough for the system - because it doesn’t necessarily go back to the beginning when it’s disabled and reenabled.
Actually just having .Play() get triggered has exactly the desired effect, I just want to do this without having to use a new script. Is there a way to trigger the particle system to play from the animation timeline?