diff --git a/SOLID/SOLID/Assets/Scenes/GameScene.unity b/SOLID/SOLID/Assets/Scenes/GameScene.unity index 3b17dae..2f78d62 100644 --- a/SOLID/SOLID/Assets/Scenes/GameScene.unity +++ b/SOLID/SOLID/Assets/Scenes/GameScene.unity @@ -973,9 +973,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: playerAnimator: {fileID: 815885425} - raycastPoint: {fileID: 1706832592} - playerMovement: {fileID: 837455035} - playerRenderer: {fileID: 815885426} ui_window: {fileID: 614753882} --- !u!82 &837455034 AudioSource: @@ -1135,6 +1132,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7169d424f5174e441a0d1fddfdc9e9ab, type: 3} m_Name: m_EditorClassIdentifier: + raycastPoint: {fileID: 1706832592} --- !u!1 &844677121 GameObject: m_ObjectHideFlags: 0 diff --git a/SOLID/SOLID/Assets/Scripts/Player.cs b/SOLID/SOLID/Assets/Scripts/Player.cs index 1f8ade9..1491e6b 100644 --- a/SOLID/SOLID/Assets/Scripts/Player.cs +++ b/SOLID/SOLID/Assets/Scripts/Player.cs @@ -1,58 +1,38 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.SceneManagement; +using UnityEngine; public class Player : MonoBehaviour { - public Animator playerAnimator; - private PlayerMovement _playerMovement; private PlayerRenderer _playerRenderer; private PlayerAIInteractions _playerAIInteractions; + private PlayerInput _playerInput; + private PlayerAnimations _playerAnimations; public GameObject ui_window; - - private Vector2 movementVector; private void Start() { + _playerAnimations = GetComponent(); _playerMovement = GetComponent(); _playerRenderer = GetComponent(); _playerAIInteractions = GetComponent(); - } - private void Update() - { - movementVector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); - movementVector.Normalize(); - if (Input.GetAxisRaw("Fire1") > 0) - { - _playerAIInteractions.Interact(_playerRenderer.IsSpriteFlipped); - } + _playerInput = GetComponent(); + + _playerInput.OnInteractEvent += () => _playerAIInteractions.Interact(_playerRenderer.IsSpriteFlipped); } private void FixedUpdate() { - MovePlayer(movementVector); - if (movementVector.magnitude > 0) + _playerMovement.MovePlayer(_playerInput.MovementInput); + _playerRenderer.RenderPlayer(_playerInput.MovementInput); + _playerAnimations.SetupAnimations(_playerInput.MovementInput); + + if (_playerInput.MovementInput.magnitude > 0) { ui_window.SetActive(false); } - else - { - playerAnimator.SetBool("Walk", false); - } } - - private void MovePlayer(Vector2 movementVector) - { - playerAnimator.SetBool("Walk", true); - _playerMovement.MovePlayer(movementVector); - - _playerRenderer.RenderPlayer(movementVector); - } - + public void ReceiveDamaged() { _playerRenderer.FlashRed(); diff --git a/SOLID/SOLID/Assets/Scripts/PlayerAnimations.cs b/SOLID/SOLID/Assets/Scripts/PlayerAnimations.cs index d28f2bf..3090eb9 100644 --- a/SOLID/SOLID/Assets/Scripts/PlayerAnimations.cs +++ b/SOLID/SOLID/Assets/Scripts/PlayerAnimations.cs @@ -1,18 +1,19 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class PlayerAnimations : MonoBehaviour { - // Start is called before the first frame update - void Start() - { - - } + [SerializeField] + private Animator playerAnimator; - // Update is called once per frame - void Update() + public void SetupAnimations(Vector2 movement) { - + if (movement.magnitude > 0) + { + playerAnimator.SetBool("Walk", true); + } + else + { + playerAnimator.SetBool("Walk", false); + } } } diff --git a/SOLID/SOLID/Assets/Scripts/PlayerInput.cs b/SOLID/SOLID/Assets/Scripts/PlayerInput.cs index bc7552a..2ad93a0 100644 --- a/SOLID/SOLID/Assets/Scripts/PlayerInput.cs +++ b/SOLID/SOLID/Assets/Scripts/PlayerInput.cs @@ -1,18 +1,29 @@ -using System.Collections; -using System.Collections.Generic; +using System; using UnityEngine; public class PlayerInput : MonoBehaviour { - // Start is called before the first frame update - void Start() + public Vector2 MovementInput { get; private set; } + + public event Action OnInteractEvent; + + private void Update() + { + GetInteractInput(); + GetMovementInput(); + } + + private void GetMovementInput() { - + MovementInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); + MovementInput.Normalize(); } - // Update is called once per frame - void Update() + private void GetInteractInput() { - + if (Input.GetAxisRaw("Fire1") > 0) + { + OnInteractEvent?.Invoke(); + } } }