Rasagar/Assets/Viking Village/Scripts/FreeCamera.cs
2024-08-26 23:07:20 +03:00

29 lines
946 B
C#

using UnityEngine;
using System.Collections;
public class FreeCamera : MonoBehaviour {
public bool freeLookEnabled = false;
public float lookSpeed = 5f;
public float moveSpeed = 5f;
public float sprintSpeed = 50f;
float m_yaw;
float m_pitch;
void Update () {
if(!freeLookEnabled)
return;
m_yaw = (m_yaw + lookSpeed * Input.GetAxis("Mouse X")) % 360f;
m_pitch = (m_pitch - lookSpeed * Input.GetAxis("Mouse Y")) % 360f;
transform.rotation = Quaternion.AngleAxis(m_yaw, Vector3.up) * Quaternion.AngleAxis(m_pitch, Vector3.right);
var speed = Time.deltaTime * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : moveSpeed);
var forward = speed * Input.GetAxis("Vertical");
var right = speed * Input.GetAxis("Horizontal");
var up = speed * ((Input.GetKey(KeyCode.Q) ? 1f : 0f) - (Input.GetKey(KeyCode.E) ? 1f : 0f));
transform.position += transform.forward * forward + transform.right * right + Vector3.up * up;
}
}