- Home /
Question by
FeastSC2 · Jul 29, 2017 at 11:16 PM ·
scripting problemparticlesystem
Changing ParticleSystem attributes at runtime
I want to change my particle system at runtime for values like Start Lifetime or Start color but it seems that most of the particle system cannot be modified (get only).
Is there a way change particle systems at runtime?
Comment
Best Answer
Answer by iBicha · Jul 30, 2017 at 02:04 AM
Hello FeastSC2
I believe you can do that. Check out the documentations example here
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
private ParticleSystem ps;
public float hSliderValue = 1.0F;
void Start()
{
ps = GetComponent<ParticleSystem>();
}
void Update()
{
var main = ps.main;
main.startLifetime = hSliderValue;
}
void OnGUI()
{
hSliderValue = GUI.HorizontalSlider(new Rect(25, 45, 100, 30), hSliderValue, 0.0F, 5.0F);
}
}