- Home /
Controlling child particle systems duration
Hello, everyone, I am currently working on some special effect.
The problem is simple, I want to control all child particle systems through the parent "Electric Blast". Not controlling everything, but just duration of lifetime. This is because, I will further adding more and more particle system in this group. If I change the duration of lifetime (or other component), it will be quite tedious.
So, I write a simple code and attached to the parent (Electric Blast).
public Component[] children;
void Start (){
children = GetComponentsInChildren<ParticleSystem>();
}
void Update(){
foreach (ParticleSystem childParticleSystem in children){
childParticleSystem.Stop();
var main = childParticleSystem.main;
main.duration = 10.0f;
childParticleSystem.Play();
}
}
What I expected is I can change the duration of every children by simply changing the number in this script.
Sure, it doesn't work, the duration of child changed but the animation doesn't play. Thus I am seeking any suggestion how to do it correctly. (Updated)
Great thanks for any ans. Bests and cheers.
Answer by ShadyProductions · Aug 09, 2017 at 07:35 AM
Updata() ?
Don't you mean Update?
Sorry for typo, but it doesn't work still, though the duration changed. The animation doesn't play.
Because it's in Update, it runs every frame. So it is stopped again every frame.
Put it all in start or something.
I tried to do so before... put it in start won't work... $$anonymous$$ay be I should try Awake?