work on switch to new input system
This commit is contained in:
@@ -30,7 +30,6 @@ public class PlayerMovement : MonoBehaviour
|
||||
public InputAction pauseGameButton;
|
||||
|
||||
|
||||
|
||||
public Transform orientation;
|
||||
public Transform cameraor;
|
||||
|
||||
@@ -47,6 +46,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
public float timeSinceLastSwing;
|
||||
public bool holdSwing;
|
||||
public float holdSwingTimer;
|
||||
public bool swingBeingHeld;
|
||||
|
||||
public float dashDistanceTimer, dashDistance, dashDuration;
|
||||
public Collider myCollider;
|
||||
@@ -64,7 +64,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
float energyObjTimer;
|
||||
public GameObject energyFill;
|
||||
|
||||
|
||||
public bool jumped;
|
||||
|
||||
|
||||
|
||||
@@ -85,12 +85,65 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
MyInput();
|
||||
if (pauseGameButton.WasPerformedThisFrame())
|
||||
|
||||
timeSinceLastSwing += Time.deltaTime;
|
||||
if (timeSinceLastSwing > .5f)
|
||||
lastSwing = 0;
|
||||
|
||||
holdSwingTimer += Time.deltaTime;
|
||||
if (holdSwing && holdSwingTimer > .15f)
|
||||
holdSwing = false;
|
||||
else if (holdSwing && GameObject.FindGameObjectsWithTag("Sword").Length < 1)
|
||||
{
|
||||
holdSwing = false;
|
||||
if (energy > 7)
|
||||
SwingSword();
|
||||
}
|
||||
if (!holdSwing)
|
||||
holdSwingTimer = 0;
|
||||
|
||||
if (swung)
|
||||
{
|
||||
swungTimer += Time.deltaTime;
|
||||
}
|
||||
if (swungTimer > 1f)
|
||||
swung = false;
|
||||
if (!swung)
|
||||
{
|
||||
swungTimer = 0;
|
||||
energy += 70 * Time.deltaTime;
|
||||
|
||||
}
|
||||
if (energy < 0)
|
||||
energy = 0;
|
||||
if (energy > 100)
|
||||
energy = 100;
|
||||
|
||||
energySlider.value = energy;
|
||||
|
||||
healthUI.sizeDelta = new Vector2((Mathf.Ceil(HP) - 1) + (9 * HP), healthUI.sizeDelta.y);
|
||||
|
||||
//MyInput();
|
||||
if (swingBeingHeld)
|
||||
{
|
||||
swung = true;
|
||||
swungTimer = 0;
|
||||
timeSinceLastSwing = 0;
|
||||
|
||||
energy -= 20 * Time.deltaTime;
|
||||
dashDistanceTimer += Time.deltaTime;
|
||||
if (dashDistanceTimer > 1)
|
||||
energyFill.GetComponent<Image>().color = Color.deepPink;
|
||||
if (energy <= 0)
|
||||
{
|
||||
if (dashDistanceTimer > 1)
|
||||
{
|
||||
dashDistance = Mathf.Floor(dashDistanceTimer * 8);
|
||||
dashDuration = 15;
|
||||
}
|
||||
dashDistanceTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (energy == 100)
|
||||
{
|
||||
@@ -106,9 +159,46 @@ public class PlayerMovement : MonoBehaviour
|
||||
energyObjTimer = 0;
|
||||
energyObj.SetActive(true);
|
||||
}
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (dashDuration > 0)
|
||||
{
|
||||
SwordDash();
|
||||
|
||||
dashDuration--;
|
||||
}
|
||||
if (dashDuration == 1)
|
||||
{
|
||||
//rb.linearVelocity = Vector3.zero;
|
||||
|
||||
dashDuration--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (canWalk /*&& !running*/)
|
||||
{
|
||||
Vector3 move = new Vector3(moveInput.x * speed, 0, moveInput.y * speed);
|
||||
Vector3 move2 = transform.TransformDirection(move);
|
||||
controller.Move(move2 * Time.deltaTime);
|
||||
}
|
||||
//else if (canWalk && running)
|
||||
//{
|
||||
// Vector3 move = new Vector3(moveInput.x * speed, 0, moveInput.y * runSpeed);
|
||||
// Vector3 move2 = transform.TransformDirection(move);
|
||||
// controller.Move(move2 * Time.deltaTime);
|
||||
//}
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
if (!controller.isGrounded)
|
||||
{
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
}
|
||||
else if (controller.isGrounded)
|
||||
{
|
||||
//velocity.y = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void PauseGame(InputAction.CallbackContext context)
|
||||
@@ -131,6 +221,72 @@ public class PlayerMovement : MonoBehaviour
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -294,7 +450,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
private void SwordDash()
|
||||
{
|
||||
myCollider.excludeLayers = excludeEnemy;
|
||||
|
||||
Debug.Log($"distance:{dashDistance}");
|
||||
//rb.AddForce(Camera.main.transform.forward * dashDistance, ForceMode.Impulse);
|
||||
swung = true;
|
||||
swungTimer = 0;
|
||||
|
||||
Reference in New Issue
Block a user