IEnumerator DyingEvent() { float elapsedTime = 0f; MovementStatus = PlayerMovementStatus.BleedingOut; //To do: Go in bleeding out animation //TIme in which the player can shoot/revived etc while (elapsedTime < playerHealth.TimeInBleedingOutState) { elapsedTime += Time.deltaTime; yield return(null); } MovementStatus = PlayerMovementStatus.Dead; elapsedTime = 0f; //To do: Go in dead animation //Maybe go in third person or something like that so you can rotate around your dead body. while (elapsedTime < playerHealth.TimeInDeadState) { elapsedTime += Time.deltaTime; yield return(null); } MovementStatus = PlayerMovementStatus.Default; playerHealth.Reset(); inventory.Reset(); GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>().RequestPlayerRespawn(gameObject); //To do: Drop all weapons from the player (fist exluded) }
public void UpdatePlayerMovementStatus(PlayerMovementStatus status, float animationDuration, bool repeatable) { currentSprite = movementStatusToSpritesheet[status]; spriteCounter = 0; currentAnimationDuration = animationDuration; isAnimationRepeatable = repeatable; if (!hasAnimationStarted) { StartCoroutine(animate()); hasAnimationStarted = true; } }
// Update is called once per frame void Update() { if (MovementStatus == PlayerMovementStatus.BleedingOut || MovementStatus == PlayerMovementStatus.Dead) { return; } //Get the W,A,S and D input and normalize it DirectionalMovementInputs = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); DirectionalMovementInputs.Normalize(); //Update the active Power Ups PowerUps?.Invoke(this, new EventArgs()); UpdateMovementStatus(); UpdateSpeed(); CurrentGun = GetComponentInChildren <WeaponSwitching>().GetActiveWeapon().GetComponent <StandardGunScript>(); if (canShoot) { if (Input.GetAxisRaw("Fire1") > 0 && CurrentGun != null) { CurrentGun.Fire(FirstPersonCamera); } } if (canMove) { Move(); } if (canRotate) { FirstPersonCamera.Rotate(); } if (canClimb) { if (animator != null) { animator.SetTrigger("Climb"); animator.ResetTrigger("Jump"); animator.ResetTrigger("Fall"); } ClimbCoroutine = StartCoroutine(ClimbEvent()); MovementStatus = PlayerMovementStatus.Climbing; } UpdateAnimationController(); }
IEnumerator Slide() { MovementStatus = PlayerMovementStatus.Sliding; float StartingSpeed = Speed * SpeedFactor / 100; float elapsedTime = 0f; Vector3 slideNormal = SlideNormal; do { Vector3 MoveThisUpdate = SlideNormal; MoveThisUpdate.y = Gravity * SlideGravityAmplifier; elapsedTime += Time.deltaTime; Controller.Move(MoveThisUpdate * Time.deltaTime * StartingSpeed); yield return(null); } while (ShouldSlide()); SlidingCoroutine = null; LastDirectionalMovementInputs = new Vector3(0, 0, 0); UpdateMovementStatus(); }
void UpdateMovementStatus() { if (JumpingCoroutine != null || FallCoroutine != null || SlidingCoroutine != null || ClimbCoroutine != null) { return; } else if (Controller.isGrounded && ShouldSlide()) { SlidingCoroutine = StartCoroutine(Slide()); } else if (!Controller.isGrounded && Controller.collisionFlags != CollisionFlags.Above && FallCoroutine == null) { FallCoroutine = StartCoroutine(FallEvent()); MovementStatus = PlayerMovementStatus.Falling; if (WindDownCouroutine != null) { StopCoroutine(WindDownCouroutine); WindDownCouroutine = null; } } else if (Input.GetKeyDown(KeyCode.Space) && Controller.isGrounded) { MovementStatus = PlayerMovementStatus.Jumping; if (WindDownCouroutine != null) { StopCoroutine(WindDownCouroutine); WindDownCouroutine = null; } if (WindUpCouroutine != null) { StopCoroutine(WindUpCouroutine); WindUpCouroutine = null; } Jump(); return; } else if (!isMovementInputZero()) { if (WindDownCouroutine == null && Speed > 0) { if (MovementStatus == PlayerMovementStatus.Jumping) { MovementStatus = PlayerMovementStatus.Idling; Speed = 0f; } WindDownCouroutine = StartCoroutine(WindDown()); } if (Speed == 0) { MovementStatus = PlayerMovementStatus.Idling; } else { MovementStatus = PlayerMovementStatus.Walking; } if (WindUpCouroutine != null) { StopCoroutine(WindUpCouroutine); WindUpCouroutine = null; } } else if (isMovementInputZero()) { if (WindDownCouroutine != null) { StopCoroutine(WindDownCouroutine); WindDownCouroutine = null; } if (Speed > 0) { MovementStatus = PlayerMovementStatus.Walking; } if (Speed == 0 && WindUpCouroutine == null) { WindUpCouroutine = StartCoroutine(WindUp()); } } }
public void animate(PlayerMovementStatus status, float animationDuration, bool repeatable) { mySpriteController.UpdatePlayerMovementStatus(status, animationDuration, repeatable); }