Version: 2021.3
public ParticleSystemSimulationSpace simulationSpace ;

描述

这可选择要在其中模拟粒子的空间。可以是世界或本地空间。

使用以下示例在本地与世界空间模拟之间切换:

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() { } }