Ausing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;
// orientation stores the direction your facing
public Transform orientation;
public Transform camHolder;
private float xRotation;
private float yRotation;
private void Start()
{
// makes cursor disappear
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
// get mouse input
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
// prevents rotation of player going past looking further than up and further from down
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
// rotate camera and orientation
camHolder.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
public void DoFov(float endValue)
{
GetComponent<Camera>().DOFieldOfView(endValue, 0.25f);
}
public void DoTilt(float zTilt)
{
transform.DOLocalRotate(new Vector3(0, 0, zTilt), 0.25f);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter