Version: 2023.2
LanguageEnglish
  • C#

ParticleSystemRenderer.sortMode

Suggest a change

Success!

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.

Close

Submission failed

For 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.

Close

Cancel

public ParticleSystemSortMode sortMode;

Description

Specifies how to sort particles within a system.

using UnityEngine;
using UnityEditor;
using System.Collections;

[RequireComponent(typeof(ParticleSystem))] public class ExampleClass : MonoBehaviour {

private ParticleSystem ps; private ParticleSystemRenderer psr; public ParticleSystemSortMode sortMode;

void Start() {

ps = GetComponent<ParticleSystem>(); psr = GetComponent<ParticleSystemRenderer>();

// set a slow start speed and high emission rate, to cause more overlap, to show sorting var main = ps.main; main.startSpeedMultiplier = 0.2f; var emission = ps.emission; emission.rateOverTimeMultiplier = 100.0f;

// set color over life, so we can see the sorting more easily var colorOverLifetime = ps.colorOverLifetime; colorOverLifetime.enabled = true;

Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) } );

colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient); }

void Update() {

psr.sortMode = sortMode; }

void OnGUI() {

sortMode = (ParticleSystemSortMode)GUI.SelectionGrid(new Rect(25, 25, 900, 30), (int)sortMode, new GUIContent[] { new GUIContent("None"), new GUIContent("Distance"), new GUIContent("OldestInFront"), new GUIContent("YoungestInFront"), new GUIContent("Depth"), new GUIContent("DistanceReverse"), new GUIContent("DepthReverse") }, 7); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961