forked from Wireline-Studios/JourneyProject
Update PlayerMovement.cs
This commit is contained in:
@@ -79,22 +79,100 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
public PlayerInput playerInput;
|
public PlayerInput playerInput;
|
||||||
|
|
||||||
InputAction jumpAction;
|
InputAction jumpAction, walkAction, attackAction, pauseAction, runAction, lookAction;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
jumpAction = playerInput.actions["Jump"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
cinemachineCam = GameObject.Find("CinemachineCamera");
|
cinemachineCam = GameObject.Find("CinemachineCamera");
|
||||||
canWalk = true;
|
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<PauseMenuControls>().mainCanvas.SetActive(false);
|
||||||
|
uiController.GetComponent<PauseMenuControls>().pauseCanvas.SetActive(true);
|
||||||
|
Time.timeScale = 0;
|
||||||
|
Cursor.lockState = CursorLockMode.None;
|
||||||
|
Cursor.visible = true;
|
||||||
|
}
|
||||||
|
else if (pauseAction.WasPressedThisFrame())
|
||||||
|
{
|
||||||
|
uiController.GetComponent<PauseMenuControls>().mainCanvas.SetActive(true);
|
||||||
|
uiController.GetComponent<PauseMenuControls>().pauseCanvas.SetActive(false);
|
||||||
|
uiController.GetComponent<PauseMenuControls>().settingsCanvas.SetActive(false);
|
||||||
|
Time.timeScale = 1;
|
||||||
|
Cursor.lockState = CursorLockMode.Locked;
|
||||||
|
Cursor.visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
moveInput = walkAction.ReadValue<Vector2>();
|
||||||
|
|
||||||
|
if (runAction.WasPressedThisFrame() && moveAnimationInputY == 1 && !running)
|
||||||
|
{
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
else if (runAction.WasPressedThisFrame() && moveAnimationInputY == 2 && running)
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
moveAnimationInputY = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
playerCam.lookInput = lookAction.ReadValue<Vector2>();
|
||||||
|
|
||||||
|
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<Image>().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()
|
void Update()
|
||||||
{
|
{
|
||||||
|
PlayerInputs();
|
||||||
|
|
||||||
timeSinceLastSwing += Time.deltaTime;
|
timeSinceLastSwing += Time.deltaTime;
|
||||||
if (timeSinceLastSwing > .5f)
|
if (timeSinceLastSwing > .5f)
|
||||||
@@ -221,92 +299,6 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
//}
|
//}
|
||||||
controller.Move(velocity * Time.deltaTime);
|
controller.Move(velocity * Time.deltaTime);
|
||||||
}
|
}
|
||||||
public void PauseGame(InputAction.CallbackContext context)
|
|
||||||
{
|
|
||||||
if (Time.timeScale == 1 && context.performed)
|
|
||||||
{
|
|
||||||
uiController.GetComponent<PauseMenuControls>().mainCanvas.SetActive(false);
|
|
||||||
uiController.GetComponent<PauseMenuControls>().pauseCanvas.SetActive(true);
|
|
||||||
Time.timeScale = 0;
|
|
||||||
Cursor.lockState = CursorLockMode.None;
|
|
||||||
Cursor.visible = true;
|
|
||||||
}
|
|
||||||
else if (context.performed)
|
|
||||||
{
|
|
||||||
uiController.GetComponent<PauseMenuControls>().mainCanvas.SetActive(true);
|
|
||||||
uiController.GetComponent<PauseMenuControls>().pauseCanvas.SetActive(false);
|
|
||||||
uiController.GetComponent<PauseMenuControls>().settingsCanvas.SetActive(false);
|
|
||||||
Time.timeScale = 1;
|
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
|
||||||
Cursor.visible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void OnMove(InputAction.CallbackContext context)
|
|
||||||
{
|
|
||||||
moveInput = context.ReadValue<Vector2>();
|
|
||||||
}
|
|
||||||
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<Vector2>();
|
|
||||||
}
|
|
||||||
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<Image>().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()
|
private void MyInput()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user