Version: 2022.3
LanguageEnglish
  • C#

ParticleSystem.LifetimeByEmitterSpeedModule.range

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

Switch to Manual
public Vector2 range;

Description

Control the start lifetime multiplier between these minimum and maximum speeds of the emitter.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(ParticleSystem))] public class ExampleClass : MonoBehaviour { private ParticleSystem ps; public bool moduleEnabled = true; public float maxSpeed = 5.0f; public AnimationCurve curve = AnimationCurve.EaseInOut(0.0f, 1.0f, 1.0f, 0.2f);

void Start() { ps = GetComponent<ParticleSystem>();

var mainModule = ps.main; mainModule.startLifetime = 1.0f;

// make particles less random to more clearly see effect of lifetime. var shapeModule = ps.shape; shapeModule.radius = 0.1f; shapeModule.angle = 1.0f;

var main = ps.main; main.simulationSpace = ParticleSystemSimulationSpace.World;

// 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 lifetimeByEmitterSpeed = ps.lifetimeByEmitterSpeed; lifetimeByEmitterSpeed.enabled = moduleEnabled; lifetimeByEmitterSpeed.range = new Vector2(0, maxSpeed); lifetimeByEmitterSpeed.curve = new ParticleSystem.MinMaxCurve(1f, curve);

ps.transform.position = new Vector3(Mathf.Sin(Time.time * 2.0f) * 4.0f, 0.0f, 0.0f); }

void OnGUI() { moduleEnabled = GUI.Toggle(new Rect(25, 45, 100, 30), moduleEnabled, "Enabled"); maxSpeed = GUI.HorizontalSlider(new Rect(25, 85, 100, 30), maxSpeed, 0.0f, 10.0f); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961