From ccb927ba61e280a674646211c833e99601583625 Mon Sep 17 00:00:00 2001 From: Vladimir Koshevarov Date: Tue, 13 Dec 2022 13:16:27 +0200 Subject: [PATCH] fix player movement and falling cycle --- Assets/Scripts/PlayerManager.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index fc6b9911..d2d3bbf1 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -27,12 +27,12 @@ public class PlayerManager : MonoBehaviour private void OnEnable() { - TimeManager.OnMinuteChanged += DecreaseEnergy; + TimeManager.OnMinuteChanged += UpdatePlayerState; } private void OnDisable() { - TimeManager.OnMinuteChanged -= DecreaseEnergy; + TimeManager.OnMinuteChanged -= UpdatePlayerState; } // Start is called before the first frame update @@ -68,18 +68,20 @@ public class PlayerManager : MonoBehaviour Vector2 velocity = (Time.deltaTime > 1e-5f) ? _groundDeltaPosition / Time.deltaTime : Vector2.zero; var shouldMove = velocity.magnitude > 0.025f && _navAgent.remainingDistance > _navAgent.radius; + if (_state != States.Sleeping) + { + _state = shouldMove ? States.Walking : States.Idle; - _state = shouldMove ? States.Walking : States.Idle; - - _animator.SetBool("Move", shouldMove); - _animator.SetFloat("velY", velocity.y); + _animator.SetBool("Move", shouldMove); + _animator.SetFloat("velY", velocity.y); + } } private void OnAnimatorMove() { transform.position = _navAgent.nextPosition; } - public void DecreaseEnergy() + public void UpdatePlayerState() { PlayerStats[StatsId.Food].deduct(0.034m); // 48 hours it's 100, 100/2880=~0.034 per minute switch (_state) @@ -96,13 +98,13 @@ public class PlayerManager : MonoBehaviour { _state = States.Sleeping; allowMovement = false; - _animator.SetBool("IsSleeping", true); + _animator.SetBool("Fall", true); } if (PlayerStats[StatsId.Energy].Value >= 100 && _state == States.Sleeping) { _state = States.Idle; - allowMovement = false; - _animator.SetBool("IsSleeping", false); + allowMovement = true; + _animator.SetBool("Fall", false); } }