Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerFallState : PlayerBaseState
- {
- public PlayerFallState(PlayerStateMachine currentContext,
- PlayerStateFactory playerStateFactory)
- : base(currentContext, playerStateFactory) {
- IsRootState = true;
- }
- public override void EnterState() {
- InitializeSubState();
- Ctx.AnimCon.SetInteger(Ctx.JumpAnim, 2);
- }
- public override void UpdateState()
- {
- CheckSwitchStates();
- if (Ctx.VerticalVelocity < Ctx.TerminalVelocity)
- {
- Ctx.VerticalVelocity += Ctx.Gravity * Time.deltaTime;
- }
- }
- public override void ExitState() {
- Ctx.AnimCon.SetInteger(Ctx.JumpAnim, 3);
- }
- public override void CheckSwitchStates() {
- if (Ctx.PlayerController.isGrounded) {
- SwitchState(Factory.Grounded());
- }
- }
- public override void InitializeSubState() {
- if (Ctx.InputMoveX == 0 && Ctx.InputMoveY == 0 && !Ctx.InputRun)
- {
- SetSubState(Factory.Idle());
- }
- else if (Ctx.InputMoveX != 0 && Ctx.InputMoveY != 0 && !Ctx.InputRun)
- {
- SetSubState(Factory.Walk());
- }
- else
- {
- SetSubState(Factory.Run());
- }
- }
- }
Add Comment
Please, Sign In to add comment