Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseChange the rate over distance multiplier.
This is more efficient than accessing the whole curve, if you only want to change the overall rate multiplier.
#pragma strict private var ps: ParticleSystem; public var hSliderValue: float = 5.0f; function Start() { ps = GetComponent.<ParticleSystem>(); var main: var = ps.main; main.simulationSpace = ParticleSystemSimulationSpace.World; // rate over distance only works for world space simulations var shape: var = ps.shape; shape.enabled = false; var emission: var = ps.emission; emission.rateOverTime = 0.0f; // add a sphere so we can see our transform position as it moves var sphere: var = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.parent = ps.transform; } function Update() { var emission: var = ps.emission; emission.rateOverDistanceMultiplier = hSliderValue; ps.transform.position = new Vector3(Mathf.Sin(Time.time) * 2.0f, 0.0f, 0.0f); } function OnGUI() { hSliderValue = GUI.HorizontalSlider(new Rect(25, 45, 100, 30), hSliderValue, 1.0f, 20.0f); }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public float hSliderValue = 5.0f;
void Start() { ps = GetComponent<ParticleSystem>();
var main = ps.main; main.simulationSpace = ParticleSystemSimulationSpace.World; // rate over distance only works for world space simulations
var shape = ps.shape; shape.enabled = false;
var emission = ps.emission; emission.rateOverTime = 0.0f;
// add a sphere so we can see our transform position as it moves var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.parent = ps.transform; }
void Update() { var emission = ps.emission; emission.rateOverDistanceMultiplier = hSliderValue;
ps.transform.position = new Vector3(Mathf.Sin(Time.time) * 2.0f, 0.0f, 0.0f); }
void OnGUI() { hSliderValue = GUI.HorizontalSlider(new Rect(25, 45, 100, 30), hSliderValue, 1.0f, 20.0f); } }