- Home /
What is the best way to assign a duration to particles?
I'm building a weather system into my latest prototype and tried to assign a length of time to particles.duration, however got the error "Property or indexer `UnityEngine.ParticleSystem.duration' cannot be assigned to (it is read only)"
If duration can't be set by code directly (in C#), what is the best way to run particles for a set period of time?
It does appear that you cannot dynamically change the lifetime of a particle system itself. However, you could create your own timer function in an update loop. After a certain accumulation of Time.deltaTime, delete the particle system.
float duration = 10.0f;
float life = 0.0f;
void Update()
{
life += Time.deltaTime;
if(life >= duration)
{
Destroy(myParticleSytem)
}
}
You can also change the lifetime of the individual particles with startLifetime http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem-startLifetime.html
DEAR @Teonnyn: Is there anything else related to we could do for you? - If so, please tell us. Else please tick an answer if it helped you solve your problem to keep the board clean and tidy, if nothing helped you, then we really appreciate FEEDBAC$$anonymous$$.
Answer by clunk47 · Sep 23, 2013 at 08:25 PM
Do you mean how long the particles live? Have a look at ParticleSystem.StartLifeTime.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour
{
void Awake()
{
particleSystem.startLifetime = .5f;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
how to use time on lerp 2 Answers