work on switch to new input system
This commit is contained in:
@@ -6,22 +6,30 @@ using UnityEngine.Rendering.PostProcessing;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed;
|
||||
public float moveSpeedMultiplier;
|
||||
public CharacterController controller;
|
||||
private Vector2 moveInput;
|
||||
private float moveAnimationInputX;
|
||||
private float moveAnimationInputY;
|
||||
private Vector3 velocity;
|
||||
public float speed;
|
||||
public float runSpeed;
|
||||
public float gravity;
|
||||
public float jumpHeight;
|
||||
public PlayerCam playerCam;
|
||||
public bool canWalk;
|
||||
float walkResetTimer;
|
||||
bool walkResetTimerGo;
|
||||
bool running;
|
||||
|
||||
|
||||
public InputAction pauseGameButton;
|
||||
|
||||
public LayerMask whatIsGround;
|
||||
public bool grounded;
|
||||
public Collider groundedCollider;
|
||||
public float airMultiplier;
|
||||
public bool airCollided;
|
||||
public bool groundCollided;
|
||||
|
||||
public float maxSlopeAngle;
|
||||
private RaycastHit slopeHit;
|
||||
private bool exitingSlope;
|
||||
|
||||
public Transform orientation;
|
||||
public Transform cameraor;
|
||||
@@ -56,36 +64,32 @@ public class PlayerMovement : MonoBehaviour
|
||||
float energyObjTimer;
|
||||
public GameObject energyFill;
|
||||
|
||||
Vector3 moveDirection;
|
||||
|
||||
|
||||
Rigidbody rb;
|
||||
|
||||
|
||||
public PhysicsMaterial walkingPhysics;
|
||||
public PhysicsMaterial standingPhysics;
|
||||
public PhysicsMaterial airColliding;
|
||||
|
||||
|
||||
public GameObject particle1;
|
||||
public GameObject particle2;
|
||||
public VolumeProfile volumeProfile;
|
||||
|
||||
|
||||
public RectTransform healthUI;
|
||||
bool jumped;
|
||||
bool jumping;
|
||||
|
||||
|
||||
public GameObject uiController;
|
||||
|
||||
void Start()
|
||||
{
|
||||
cinemachineCam = GameObject.Find("CinemachineCamera");
|
||||
rb = GetComponent<Rigidbody>();
|
||||
rb.freezeRotation = true;
|
||||
|
||||
canWalk = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
MyInput();
|
||||
SpeedControl();
|
||||
if (pauseGameButton.WasPerformedThisFrame())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (energy == 100)
|
||||
@@ -105,111 +109,42 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
MovePlayer();
|
||||
|
||||
}
|
||||
public void PauseGame(InputAction.CallbackContext context)
|
||||
{
|
||||
if (Time.timeScale == 1 && context.performed)
|
||||
{
|
||||
uiController.GetComponent<PauseMenuControls>().mainCanvas.enabled = false;
|
||||
uiController.GetComponent<PauseMenuControls>().pauseCanvas.enabled = true;
|
||||
Time.timeScale = 0;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
else if (context.performed)
|
||||
{
|
||||
uiController.GetComponent<PauseMenuControls>().mainCanvas.enabled = true;
|
||||
uiController.GetComponent<PauseMenuControls>().pauseCanvas.enabled = false;
|
||||
uiController.GetComponent<PauseMenuControls>().settingsCanvas.enabled = false;
|
||||
Time.timeScale = 1;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
private void MyInput()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Alpha7))
|
||||
{
|
||||
HP -= 1;
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha8))
|
||||
{
|
||||
HP -= .5f;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.Alpha9))
|
||||
{
|
||||
HP -= Time.deltaTime;
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha6))
|
||||
{
|
||||
HP = 10;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Alpha1))
|
||||
{
|
||||
inventorySlot = 1;
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha2))
|
||||
{
|
||||
inventorySlot = 2;
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha3))
|
||||
{
|
||||
inventorySlot = 3;
|
||||
}
|
||||
if (inventorySlot > 3)
|
||||
inventorySlot = 3;
|
||||
if (inventorySlot < 1)
|
||||
inventorySlot = 1;
|
||||
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
if (Time.timeScale == 1)
|
||||
{
|
||||
uiController.GetComponent<PauseMenuControls>().mainCanvas.enabled = false;
|
||||
uiController.GetComponent<PauseMenuControls>().pauseCanvas.enabled = true;
|
||||
Time.timeScale = 0;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
uiController.GetComponent<PauseMenuControls>().mainCanvas.enabled = true;
|
||||
uiController.GetComponent<PauseMenuControls>().pauseCanvas.enabled = false;
|
||||
uiController.GetComponent<PauseMenuControls>().settingsCanvas.enabled = false;
|
||||
Time.timeScale = 1;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
horizontalInput = Input.GetAxisRaw("Horizontal");
|
||||
verticalInput = Input.GetAxisRaw("Vertical");
|
||||
if (horizontalInput == 0 && verticalInput == 0 && grounded && !Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
rb.linearDamping = 7;
|
||||
|
||||
GetComponent<CapsuleCollider>().material = standingPhysics;
|
||||
}
|
||||
else if (horizontalInput != 0 || verticalInput != 0 || !grounded || Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
rb.linearDamping = 0;
|
||||
|
||||
GetComponent<CapsuleCollider>().material = walkingPhysics;
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Space) && grounded)
|
||||
{
|
||||
rb.linearDamping = 0;
|
||||
|
||||
GetComponent<CapsuleCollider>().material = walkingPhysics;
|
||||
jumped = true;
|
||||
jumping = true;
|
||||
}
|
||||
|
||||
if (jumped)
|
||||
{
|
||||
rb.linearDamping = 0;
|
||||
|
||||
GetComponent<CapsuleCollider>().material = walkingPhysics;
|
||||
if (jumping)
|
||||
{
|
||||
rb.AddForce(Vector3.up * 6, ForceMode.Impulse);
|
||||
jumping = false;
|
||||
}
|
||||
}
|
||||
if (airCollided && !grounded)
|
||||
{
|
||||
rb.linearDamping = 0;
|
||||
GetComponent<CapsuleCollider>().material = airColliding;
|
||||
//rb.AddForce(Vector3.down * 1, ForceMode.Force);
|
||||
Debug.Log("ng, hs");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -313,10 +248,6 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
private void LateUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
private void SwingSword()
|
||||
{
|
||||
@@ -345,21 +276,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
private void MovePlayer()
|
||||
{
|
||||
moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
|
||||
|
||||
|
||||
if (grounded)
|
||||
rb.AddForce(moveDirection.normalized * moveSpeed * moveSpeedMultiplier * 3, ForceMode.Force);
|
||||
|
||||
else if (!grounded)
|
||||
rb.AddForce(moveDirection.normalized * moveSpeed * moveSpeedMultiplier * airMultiplier, ForceMode.Force);
|
||||
|
||||
|
||||
|
||||
if (rb.linearVelocity.y < -1)
|
||||
{
|
||||
rb.AddForce(transform.up * -5, ForceMode.Force);
|
||||
}
|
||||
|
||||
|
||||
if (dashDuration > 0)
|
||||
{
|
||||
@@ -369,7 +286,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
if (dashDuration == 1)
|
||||
{
|
||||
rb.linearVelocity = Vector3.zero;
|
||||
//rb.linearVelocity = Vector3.zero;
|
||||
|
||||
dashDuration--;
|
||||
}
|
||||
@@ -378,90 +295,11 @@ public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
myCollider.excludeLayers = excludeEnemy;
|
||||
|
||||
rb.AddForce(Camera.main.transform.forward * dashDistance, ForceMode.Impulse);
|
||||
//rb.AddForce(Camera.main.transform.forward * dashDistance, ForceMode.Impulse);
|
||||
swung = true;
|
||||
swungTimer = 0;
|
||||
timeSinceLastSwing = 0;
|
||||
}
|
||||
private void SpeedControl()
|
||||
{
|
||||
|
||||
{
|
||||
Vector3 flatVel = new Vector3(rb.linearVelocity.x, 0f, rb.linearVelocity.z);
|
||||
|
||||
if (flatVel.magnitude > moveSpeed)
|
||||
{
|
||||
Vector3 limitedVel = flatVel.normalized * moveSpeed;
|
||||
rb.linearVelocity = new Vector3(limitedVel.x, rb.linearVelocity.y, limitedVel.z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private bool OnSlope()
|
||||
{
|
||||
|
||||
if (Physics.Raycast(transform.position, Vector3.down, out slopeHit, 2 * 0.5f + 0.3f))
|
||||
{
|
||||
float angle = Vector3.Angle(Vector3.up, slopeHit.normal);
|
||||
return angle < maxSlopeAngle && angle != 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
private Vector3 GetSlopeDirection()
|
||||
{
|
||||
return Vector3.ProjectOnPlane(moveDirection, slopeHit.normal).normalized;
|
||||
}
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.gameObject.tag == "Enemy")
|
||||
{
|
||||
HP--;
|
||||
}
|
||||
if (!other.isTrigger/* && other.gameObject.tag == "Ground"*/)
|
||||
{
|
||||
|
||||
grounded = true;
|
||||
if (jumped)
|
||||
jumped = false;
|
||||
}
|
||||
}
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
if (!other.isTrigger/* && other.gameObject.tag == "Ground"*/)
|
||||
{
|
||||
|
||||
grounded = true;
|
||||
}
|
||||
}
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (!other.isTrigger/* && other.gameObject.tag == "Ground"*/)
|
||||
{
|
||||
grounded = false;
|
||||
}
|
||||
}
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (!grounded)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
private void OnCollisionStay(Collision collision)
|
||||
{
|
||||
if (!grounded)
|
||||
{
|
||||
airCollided = true;
|
||||
|
||||
}
|
||||
}
|
||||
private void OnCollisionExit(Collision collision)
|
||||
{
|
||||
if (!grounded)
|
||||
{
|
||||
airCollided = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user