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

46 行
1.2 KiB

using UnityEngine;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(menuName = "State Machines/Actions/Play Land Particles")]
public class PlayLandParticlesActionSO : StateActionSO<PlayLandParticlesAction> { }
public class PlayLandParticlesAction : StateAction
{
//Component references
private DustParticlesController _dustController;
private Transform _transform;
private float _coolDown = 0.3f;
private float t = 0f;
private float _fallStartY = 0f;
private float _fallEndY = 0f;
private float _maxFallDistance = 4f; //Used to adjust particle emission intensity
public override void Awake(StateMachine stateMachine)
{
_dustController = stateMachine.GetComponent<DustParticlesController>();
_transform = stateMachine.transform;
}
public override void OnStateEnter()
{
_fallStartY = _transform.position.y;
}
public override void OnStateExit()
{
_fallEndY = _transform.position.y;
float dY = Mathf.Abs(_fallStartY - _fallEndY);
float fallIntensity = Mathf.InverseLerp(0, _maxFallDistance, dY);
if (Time.time >= t + _coolDown)
{
_dustController.PlayLandParticles(fallIntensity);
t = Time.time;
}
}
public override void OnUpdate() { }
}