71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.TEM
|
|
{
|
|
public class FlyCam : MonoBehaviour
|
|
{
|
|
public float cameraSensitivity = 90f;
|
|
|
|
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 * Time.deltaTime;
|
|
rotationY += Input.GetAxis("Mouse Y") * cameraSensitivity * Time.deltaTime;
|
|
rotationY = Mathf.Clamp(rotationY, -90f, 90f);
|
|
base.transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
|
|
base.transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
|
|
Vector3 vector = base.transform.right * normalMoveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;
|
|
Vector3 vector2 = base.transform.forward * normalMoveSpeed * Input.GetAxis("Vertical") * Time.deltaTime;
|
|
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
|
|
{
|
|
vector *= fastMoveFactor;
|
|
vector2 *= fastMoveFactor;
|
|
}
|
|
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
|
|
{
|
|
vector *= slowMoveFactor;
|
|
vector2 *= slowMoveFactor;
|
|
}
|
|
base.transform.position += vector;
|
|
base.transform.position += vector2;
|
|
if (Input.GetKey(KeyCode.Space))
|
|
{
|
|
base.transform.position += base.transform.up * climbSpeed * Time.deltaTime;
|
|
}
|
|
if (Input.GetKey(KeyCode.C))
|
|
{
|
|
base.transform.position -= base.transform.up * climbSpeed * Time.deltaTime;
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.End))
|
|
{
|
|
if (Cursor.lockState == CursorLockMode.Locked)
|
|
{
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
}
|
|
else
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
Cursor.visible = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|