这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

68 行
1.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UOP1.StateMachine;
/// <summary>
/// Controls playback of particles connected to movement. Methods invoked by the StateMachine StateActions
/// </summary>
public class DustParticlesController : MonoBehaviour
{
[SerializeField] ParticleSystem _walkingParticles = default;
[SerializeField] ParticleSystem _landParticles = default;
[SerializeField] ParticleSystem _jumpParticles = default;
public void EnableWalkParticles()
{
_walkingParticles.Play();
}
public void DisableWalkParticles()
{
_walkingParticles.Stop();
}
public void PlayJumpParticles()
{
_jumpParticles.Play();
}
public void PlayLandParticles()
{
_landParticles.Play();
}
public void PlayLandParticles(float intensity)
{
// make sure intensity is always between 0 and 1
intensity = Mathf.Clamp01(intensity);
ParticleSystem.MainModule main = _landParticles.main;
ParticleSystem.MinMaxCurve origCurve = main.startSize; //save original curve to be assigned back to particle system
ParticleSystem.MinMaxCurve newCurve = main.startSize; //Make a new minMax curve and make our changes to the new copy
float minSize = newCurve.constantMin;
float maxSize = newCurve.constantMax;
// use the intensity to change the maximum size of the particle curve
newCurve.constantMax = Mathf.Lerp(minSize, maxSize, intensity);
main.startSize = newCurve;
_landParticles.Play();
// Put the original startSize back where you found it
StartCoroutine(ResetMinMaxCurve(_landParticles, origCurve));
// Note: We don't necessarily need to reset the curve, as it will be overridden
}
private IEnumerator ResetMinMaxCurve(ParticleSystem ps, ParticleSystem.MinMaxCurve curve)
{
while (ps.isEmitting)
{
yield return null;
}
ParticleSystem.MainModule main = ps.main;
main.startSize = curve;
}
}