这选择模拟粒子的空间。它可以是世界空间或局部空间。
使用以下示例在局部空间和世界空间模拟之间切换
using UnityEngine; using System.Collections;
[RequireComponent(typeof(ParticleSystem))] public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public bool useLocal = true;
void Start() { ps = GetComponent<ParticleSystem>(); var main = ps.main; useLocal = main.simulationSpace == ParticleSystemSimulationSpace.Local; }
void Update() { var main = ps.main; main.simulationSpace = useLocal ? ParticleSystemSimulationSpace.Local : ParticleSystemSimulationSpace.World; }
void OnGUI() { useLocal = GUI.Toggle(new Rect(10, 60, 200, 30), useLocal, "Use Local Simulation Space"); } }
使用以下示例相对于独立的游戏对象模拟粒子
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ParticleSystemScript : MonoBehaviour { private ParticleSystem ps; public Transform relativeTo;
void Start() { ps = GetComponent<ParticleSystem>();
var main = ps.main; main.simulationSpace = ParticleSystemSimulationSpace.Custom; main.customSimulationSpace = relativeTo; }
void Update() { } }