Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerJumpState : PlayerBaseState
- {
- public PlayerJumpState(PlayerStateMachine currentContext,
- PlayerStateFactory playerStateFactory)
- : base(currentContext, playerStateFactory) {
- IsRootState = true;
- }
- public override void EnterState() {
- InitializeSubState();
- //Ctx.AnimCon.SetInteger(Ctx.JumpAnim, 1);
- HandleJump();
- }
- public override void UpdateState() {
- CheckSwitchStates();
- HandleGravity();
- }
- public override void ExitState() {
- //SwitchState(Factory.Fall());
- Ctx.AnimCon.SetInteger(Ctx.JumpAnim, 4);
- }
- public override void InitializeSubState() {
- }
- public override void CheckSwitchStates() {
- //SwitchState(Factory.Fall());
- //Debug.Log("FallJump");
- if (Ctx.PlayerController.isGrounded) {
- SwitchState(Factory.Grounded());
- }
- }
- void HandleJump() {
- //-- Jump Animation --//
- //animator.SetInteger("jumpState", 1);
- Ctx.VerticalVelocity = Mathf.Sqrt(Ctx.JumpHeight * -2f * Ctx.Gravity);
- }
- public void HandleGravity()
- {
- if (Ctx.VerticalVelocity < Ctx.TerminalVelocity)
- {
- Ctx.VerticalVelocity += Ctx.Gravity * Time.deltaTime;
- }
- }
- }
Add Comment
Please, Sign In to add comment