版本: Unity 6 (6000.0)
语言英语
  • C#

ParticleSystem.LifetimeByEmitterSpeedModule.curve

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实会阅读用户提出的每项更改建议,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的更改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

切换到手册

描述

使用此曲线来定义一个值,该值根据粒子生成时发射器的速度来乘以粒子的起始生存时间。

请注意,您应该将此曲线设置为ParticleSystemCurveMode.CurveParticleSystemCurveMode.TwoCurves 以便提供任何值,因为将其设置为 ParticleSystemCurveMode.ConstantParticleSystemCurveMode.TwoConstants 不会执行任何无法通过仅使用 ParticleSystem.MainModule.startLifetime 完成的操作。

其他资源: MinMaxCurve.

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); } }