Files
UltimateFishing2020/Assets/Scripts/Assembly-CSharp/ExtendedFlycam.cs
2026-03-04 10:03:45 +08:00

59 lines
2.1 KiB
C#

using UnityEngine;
public class ExtendedFlycam : MonoBehaviour
{
public float cameraSensitivity = 3f;
public float climbSpeed = 4f;
public float normalMoveSpeed = 10f;
public float slowMoveFactor = 0.25f;
public float fastMoveFactor = 3f;
private float rotationX;
private float rotationY;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
rotationX += Input.GetAxis("Mouse X") * cameraSensitivity;
rotationY += Input.GetAxis("Mouse Y") * cameraSensitivity;
rotationY = Mathf.Clamp(rotationY, -90f, 90f);
if (Mathf.Abs(Input.GetAxis("Mouse X")) > 0f || Mathf.Abs(Input.GetAxis("Mouse Y")) > 0f)
{
base.transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
base.transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
}
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
base.transform.position += base.transform.forward * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime;
base.transform.position += base.transform.right * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime;
}
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
base.transform.position += base.transform.forward * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime;
base.transform.position += base.transform.right * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime;
}
else if (Mathf.Abs(Input.GetAxis("Vertical")) > 0f || Mathf.Abs(Input.GetAxis("Horizontal")) > 0f)
{
base.transform.position += base.transform.forward * normalMoveSpeed * Input.GetAxis("Vertical") * Time.deltaTime;
base.transform.position += base.transform.right * normalMoveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;
}
if (Input.GetKey(KeyCode.Q))
{
base.transform.position += base.transform.up * climbSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.E))
{
base.transform.position -= base.transform.up * climbSpeed * Time.deltaTime;
}
}
}