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

40 行
1.4 KiB

using UnityEngine;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "Ascend", menuName = "State Machines/Actions/Ascend")]
public class AscendActionSO : StateActionSO<AscendAction>
{
[Tooltip("The initial upwards push when pressing jump. This is injected into verticalMovement, and gradually cancelled by gravity")]
public float initialJumpForce = 6f;
}
public class AscendAction : StateAction
{
//Component references
private Protagonist _protagonistScript;
private float _verticalMovement;
private float _gravityContributionMultiplier;
private AscendActionSO _originSO => (AscendActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{
_protagonistScript = stateMachine.GetComponent<Protagonist>();
}
public override void OnStateEnter()
{
_verticalMovement = _originSO.initialJumpForce;
}
public override void OnUpdate()
{
_gravityContributionMultiplier += Protagonist.GRAVITY_COMEBACK_MULTIPLIER;
_gravityContributionMultiplier *= Protagonist.GRAVITY_DIVIDER; //Reduce the gravity effect
_verticalMovement += Physics.gravity.y * Protagonist.GRAVITY_MULTIPLIER * Time.deltaTime * _gravityContributionMultiplier;
//Note that even if it's added, the above value is negative due to Physics.gravity.y
_protagonistScript.movementVector.y = _verticalMovement;
}
}