studycase2

This commit is contained in:
2025-11-24 21:29:46 +08:00
parent 749719e862
commit 173fe7574b
608 changed files with 52537 additions and 39 deletions

View File

@@ -0,0 +1,41 @@
using UnityEngine;
namespace Boxophobic.Utility
{
public class CamController : MonoBehaviour
{
public float movementSpeed = 5f;
public float accelerationMultiplier = 2f;
public float sensitivity = 2f;
private float yaw = 0f;
private float pitch = 0f;
void Start()
{
// Store the initial rotation of the camera
yaw = transform.eulerAngles.y;
pitch = transform.eulerAngles.x;
}
void Update()
{
float currentSpeed = movementSpeed;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
currentSpeed *= accelerationMultiplier;
}
float horizontalMovement = Input.GetAxis("Horizontal") * currentSpeed * Time.deltaTime;
float verticalMovement = Input.GetAxis("Vertical") * currentSpeed * Time.deltaTime;
transform.Translate(horizontalMovement, 0, verticalMovement);
yaw += sensitivity * Input.GetAxis("Mouse X");
pitch -= sensitivity * Input.GetAxis("Mouse Y");
pitch = Mathf.Clamp(pitch, -90f, 90f);
transform.rotation = Quaternion.Euler(pitch, yaw, 0f);
}
}
}