scroll to increase and decrease walk speed
This commit is contained in:
parent
a55e58a15c
commit
59f320622e
@ -26,6 +26,11 @@ public class FirstPersonController : MonoBehaviour
|
|||||||
[SerializeField] private KeyCode crouchKey = KeyCode.C;
|
[SerializeField] private KeyCode crouchKey = KeyCode.C;
|
||||||
|
|
||||||
[Header("Movement Parameters")]
|
[Header("Movement Parameters")]
|
||||||
|
[SerializeField] private float minWalkSpeed = 1.0f;
|
||||||
|
[SerializeField] private float maxWalkSpeed = 5.0f;
|
||||||
|
[SerializeField] private float walkSpeedInterval = 0.5f;
|
||||||
|
private float currentWalkSpeed;
|
||||||
|
|
||||||
[SerializeField] private float walkSpeed = 3.0f;
|
[SerializeField] private float walkSpeed = 3.0f;
|
||||||
[SerializeField] private float sprintSpeed = 6.0f;
|
[SerializeField] private float sprintSpeed = 6.0f;
|
||||||
[SerializeField] private float crouchSpeed = 1.5f;
|
[SerializeField] private float crouchSpeed = 1.5f;
|
||||||
@ -75,6 +80,7 @@ public class FirstPersonController : MonoBehaviour
|
|||||||
defaultYPos = playerCamera.transform.localPosition.y;
|
defaultYPos = playerCamera.transform.localPosition.y;
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
Cursor.lockState = CursorLockMode.Locked;
|
||||||
Cursor.visible = false;
|
Cursor.visible = false;
|
||||||
|
currentWalkSpeed = walkSpeed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +101,7 @@ public class FirstPersonController : MonoBehaviour
|
|||||||
CanMove = true;
|
CanMove = true;
|
||||||
HandleMovementInput();
|
HandleMovementInput();
|
||||||
HandleMouseLook();
|
HandleMouseLook();
|
||||||
|
HandleSpeedChange();
|
||||||
|
|
||||||
if (canJump)
|
if (canJump)
|
||||||
HandleJump();
|
HandleJump();
|
||||||
@ -190,5 +197,29 @@ public class FirstPersonController : MonoBehaviour
|
|||||||
|
|
||||||
duringCrouchAnimation = false;
|
duringCrouchAnimation = false;
|
||||||
}
|
}
|
||||||
|
private void HandleSpeedChange()
|
||||||
|
{
|
||||||
|
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||||
|
|
||||||
|
if (scroll > 0)
|
||||||
|
{
|
||||||
|
// Increase walk speed if within the maximum limit
|
||||||
|
if (currentWalkSpeed < maxWalkSpeed)
|
||||||
|
{
|
||||||
|
currentWalkSpeed += walkSpeedInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (scroll < 0)
|
||||||
|
{
|
||||||
|
// Decrease walk speed if within the minimum limit
|
||||||
|
if (currentWalkSpeed > minWalkSpeed)
|
||||||
|
{
|
||||||
|
currentWalkSpeed -= walkSpeedInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the walk speed
|
||||||
|
walkSpeed = currentWalkSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user