diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index c5e8fb9..87b5f1a 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -79,22 +79,100 @@ public class PlayerMovement : MonoBehaviour public PlayerInput playerInput; - InputAction jumpAction; + InputAction jumpAction, walkAction, attackAction, pauseAction, runAction, lookAction; private void Awake() { - jumpAction = playerInput.actions["Jump"]; + } void Start() { cinemachineCam = GameObject.Find("CinemachineCamera"); canWalk = true; - } + jumpAction = playerInput.actions["Jump"]; + walkAction = playerInput.actions["Walk"]; + attackAction = playerInput.actions["Attack"]; + pauseAction = playerInput.actions["Pause"]; + runAction = playerInput.actions["Run"]; + lookAction = playerInput.actions["Look"]; + } + void PlayerInputs() + { + if (pauseAction.WasPressedThisFrame() && Time.timeScale == 1) + { + uiController.GetComponent().mainCanvas.SetActive(false); + uiController.GetComponent().pauseCanvas.SetActive(true); + Time.timeScale = 0; + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + else if (pauseAction.WasPressedThisFrame()) + { + uiController.GetComponent().mainCanvas.SetActive(true); + uiController.GetComponent().pauseCanvas.SetActive(false); + uiController.GetComponent().settingsCanvas.SetActive(false); + Time.timeScale = 1; + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + + moveInput = walkAction.ReadValue(); + + if (runAction.WasPressedThisFrame() && moveAnimationInputY == 1 && !running) + { + running = true; + } + else if (runAction.WasPressedThisFrame() && moveAnimationInputY == 2 && running) + { + running = false; + moveAnimationInputY = 1; + } + + playerCam.lookInput = lookAction.ReadValue(); + + if (attackAction.WasPressedThisFrame() && inventorySlot == 1) + { + swingBeingHeld = true; + if (GameObject.FindGameObjectsWithTag("Sword").Length < 1) + { + if (energy > 7) + SwingSword(); + } + else + { + swung = true; + swungTimer = 0; + holdSwingTimer = 0; + holdSwing = true; + } + } + if (attackAction.WasReleasedThisFrame() && inventorySlot == 1) + { + swingBeingHeld = false; + energyFill.GetComponent().color = Color.darkRed; + if (dashDistanceTimer > 1) + { + dashDistance = Mathf.Floor(dashDistanceTimer * 8); + dashDuration = 15; + } + dashDistanceTimer = 0; + } + + if (jumpAction.WasPressedThisFrame() && controller.isGrounded) + { + velocity.y = Mathf.Sqrt(jumpHeight * -1f * gravity); + jumped = true; + } + if (jumpAction.WasReleasedThisFrame() && !controller.isGrounded) + { + jumped = false; + } + } void Update() { - + PlayerInputs(); timeSinceLastSwing += Time.deltaTime; if (timeSinceLastSwing > .5f) @@ -221,92 +299,6 @@ public class PlayerMovement : MonoBehaviour //} controller.Move(velocity * Time.deltaTime); } - public void PauseGame(InputAction.CallbackContext context) - { - if (Time.timeScale == 1 && context.performed) - { - uiController.GetComponent().mainCanvas.SetActive(false); - uiController.GetComponent().pauseCanvas.SetActive(true); - Time.timeScale = 0; - Cursor.lockState = CursorLockMode.None; - Cursor.visible = true; - } - else if (context.performed) - { - uiController.GetComponent().mainCanvas.SetActive(true); - uiController.GetComponent().pauseCanvas.SetActive(false); - uiController.GetComponent().settingsCanvas.SetActive(false); - Time.timeScale = 1; - Cursor.lockState = CursorLockMode.Locked; - Cursor.visible = false; - } - } - public void OnMove(InputAction.CallbackContext context) - { - moveInput = context.ReadValue(); - } - public void OnRun(InputAction.CallbackContext context) - { - if (context.performed && moveAnimationInputY == 1 && !running) - { - running = true; - } - else if (context.performed && moveAnimationInputY == 2 && running) - { - running = false; - moveAnimationInputY = 1; - } - if (context.canceled) - { - //running = false; - } - } - public void OnLook(InputAction.CallbackContext context) - { - playerCam.lookInput = context.ReadValue(); - } - public void OnAttack(InputAction.CallbackContext context) - { - if (context.performed && inventorySlot == 1) - { - swingBeingHeld = true; - if (GameObject.FindGameObjectsWithTag("Sword").Length < 1) - { - if (energy > 7) - SwingSword(); - } - else - { - swung = true; - swungTimer = 0; - holdSwingTimer = 0; - holdSwing = true; - } - } - if (context.canceled && inventorySlot == 1) - { - swingBeingHeld = false; - energyFill.GetComponent().color = Color.darkRed; - if (dashDistanceTimer > 1) - { - dashDistance = Mathf.Floor(dashDistanceTimer * 8); - dashDuration = 15; - } - dashDistanceTimer = 0; - } - } - public void OnJump(InputAction.CallbackContext context) - { - if (context.performed && controller.isGrounded) - { - velocity.y = Mathf.Sqrt(jumpHeight * -1f * gravity); - jumped = true; - } - if (context.canceled && !controller.isGrounded) - { - jumped = false; - } - } private void MyInput() {