发射器根据距离生成新粒子的速率。
发射器只有在移动时才会生成新的粒子。如果系统的 GameObject 包含 Rigidbody 或 Rigidbody2D 组件,并且系统的 发射器速度 属性设置为 刚体,Unity 会根据刚体的速度计算距离。否则,Unity 会根据 GameObject 的 Transform 组件自上次更新以来移动的距离计算距离。其他资源:MinMaxCurve,ParticleSystem.EmissionModule.rateOverTime,ParticleSystem.MainModule.emitterVelocityMode。
using UnityEngine; using System.Collections;
[RequireComponent(typeof(ParticleSystem))] 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;
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.rateOverDistance = 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); } }