您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
40 行
1.4 KiB
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;
|
|
}
|
|
}
|