diff --git a/Assets/Scripts/Core/Player/Player.cs b/Assets/Scripts/Core/Player/Player.cs index 83ec7abf2ce6dea790fd5c9ceed0a74b7bcff564..24b45f975dd872f51aa4aa83e3df3ab4b390bf00 100644 --- a/Assets/Scripts/Core/Player/Player.cs +++ b/Assets/Scripts/Core/Player/Player.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -5,15 +6,14 @@ using UnityEngine; public class Player : RigidObject{ private PlayerAnimationController animationController; private PlayerMovementController movementController; - private PlayerStateController stateController; + public PlayerStateController stateController; public PlayerStats stats; - public int State => stateController.state; new void Start(){ base.Start(); - animationController = new PlayerAnimationController(this); - movementController = new PlayerMovementController(this); stateController = new PlayerStateController(this); + movementController = new PlayerMovementController(this); + animationController = new PlayerAnimationController(this); stats = new PlayerStats(this); } diff --git a/Assets/Scripts/Core/Player/PlayerAnimationController.cs b/Assets/Scripts/Core/Player/PlayerAnimationController.cs index bb2c6850ddd819431f971e12d1ed5c886c395633..b59864afbd0ec07466144852026f53a0448e0152 100644 --- a/Assets/Scripts/Core/Player/PlayerAnimationController.cs +++ b/Assets/Scripts/Core/Player/PlayerAnimationController.cs @@ -1,9 +1,35 @@ +using UnityEngine; + public class PlayerAnimationController{ + // Consts + private const string IDLE_TRIGGER = "idle_param"; + private const string WALK_TRIGGER = "walk_param"; + // Attributes private Player player; + private PlayerStateController playerStateController; + private Transform modelTransform; + private Animator animator; // Constructor public PlayerAnimationController(Player player){ this.player = player; + modelTransform = player.transform.Find("Model"); + animator = modelTransform.GetComponent<Animator>(); + + player.stateController.OnStateChange += Animate; + } + + public void Animate(){ + Debug.Log("State changed " + player.stateController.state); + + switch (player.stateController.state){ + case PlayerState.IDLE: + animator.SetBool(IDLE_TRIGGER, true); + break; + case PlayerState.WALKING: + animator.SetBool(WALK_TRIGGER, true); + break; + } } } diff --git a/Assets/Scripts/Core/Player/PlayerStats.cs b/Assets/Scripts/Core/Player/PlayerStats.cs index 019dd11e946772121132bb2bc483cbf7578a42e9..e53edcca1e60821030fd30186a11d5c598bf47b8 100644 --- a/Assets/Scripts/Core/Player/PlayerStats.cs +++ b/Assets/Scripts/Core/Player/PlayerStats.cs @@ -6,7 +6,7 @@ public class PlayerStats { public float jumpForce = 600; public float snapshotSpeed = 25; - public float MaxSpeed => player.State switch{ + public float MaxSpeed => player.stateController.state switch{ PlayerState.WALKING => walkSpeed, PlayerState.SPRINTING => sprintSpeed, PlayerState.JUMPING => snapshotSpeed, diff --git a/Assets/Scripts/Library/BaseClasses/RigidObject.cs b/Assets/Scripts/Library/BaseClasses/RigidObject.cs index 145c562016a44e144791b1273f93b908eaf02a00..4964e29a8efba75b28282d61abf9016910ab79d2 100644 --- a/Assets/Scripts/Library/BaseClasses/RigidObject.cs +++ b/Assets/Scripts/Library/BaseClasses/RigidObject.cs @@ -6,7 +6,9 @@ public class RigidObject : MonoBehaviour { // Readonly by others private new Rigidbody rigidbody; private new Collider collider; - private bool grounded; + + //TODO: grounded automatic detection + private bool grounded = true; public Rigidbody Rigidbody => rigidbody;