控制粒子系统如何将它的 Transform 组件应用到它发射的粒子。
层次结构: 按照它的 Transform 及其所有父级进行缩放。局部: 仅使用它自己的 Transform 进行缩放,忽略所有父级。形状: 仅将缩放应用于粒子的源位置,但不应用于它们的大小。源位置由形状模块定义。
using UnityEngine; using System.Collections;
// add this to a Particle System which has a parent game object, to see how each scaling mode works public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public float sliderValue = 1.0F; public float parentSliderValue = 1.0F; public ParticleSystemScalingMode scaleMode;
void Start() { ps = GetComponent<ParticleSystem>(); }
void Update() { ps.transform.localScale = new Vector3(sliderValue, sliderValue, sliderValue); if (ps.transform.parent != null) ps.transform.parent.localScale = new Vector3(parentSliderValue, parentSliderValue, parentSliderValue);
var main = ps.main; main.scalingMode = scaleMode; }
void OnGUI() { scaleMode = (ParticleSystemScalingMode)GUI.SelectionGrid(new Rect(25, 25, 300, 30), (int)scaleMode, new GUIContent[] { new GUIContent("Hierarchy"), new GUIContent("Local"), new GUIContent("Shape") }, 3); GUI.Label(new Rect(25, 80, 100, 30), "Scale"); sliderValue = GUI.HorizontalSlider(new Rect(125, 85, 100, 30), sliderValue, 0.0F, 5.0F); GUI.Label(new Rect(25, 120, 100, 30), "Parent Scale"); parentSliderValue = GUI.HorizontalSlider(new Rect(125, 125, 100, 30), parentSliderValue, 0.0F, 5.0F); } }