41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Cinemachine;
|
|
|
|
public class CameraController : MonoBehaviour {
|
|
private Vector2 mousePos;
|
|
|
|
private Vector2 worldSize;
|
|
private float mouseSens = 200f;
|
|
private float moveSpeed = 100f;
|
|
|
|
void Start() {
|
|
mousePos = Input.mousePosition;
|
|
}
|
|
|
|
void Update() {
|
|
|
|
// Camera Rotation
|
|
if (Input.GetMouseButton(0)) {
|
|
float yawDelta = mouseSens * Time.deltaTime * Input.GetAxis("Mouse X");
|
|
float pitchDelta = mouseSens * Time.deltaTime * Input.GetAxis("Mouse Y");
|
|
pitchDelta = Mathf.Clamp(pitchDelta, -90f, 90f);
|
|
|
|
transform.Rotate(Vector3.up * yawDelta, Space.World);
|
|
transform.Rotate(Vector3.left * pitchDelta);
|
|
}
|
|
|
|
// Camera Movement
|
|
if (Input.GetMouseButton(1)) {
|
|
Vector2 delta = new Vector2(
|
|
(Input.mousePosition.x - mousePos.x) * moveSpeed * Time.deltaTime,
|
|
(Input.mousePosition.y - mousePos.y) * moveSpeed * Time.deltaTime
|
|
) * -1;
|
|
transform.position += new Vector3(delta.x, delta.y, 0.0f);
|
|
}
|
|
|
|
mousePos = Input.mousePosition;
|
|
}
|
|
}
|