Skip to content

Instantly share code, notes, and snippets.

@MrSimsek
Last active August 15, 2021 18:57
Show Gist options
  • Save MrSimsek/70a361472a30e93fec74910773115bce to your computer and use it in GitHub Desktop.
Save MrSimsek/70a361472a30e93fec74910773115bce to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControl : MonoBehaviour {
[SerializeField]
private GameObject player;
[SerializeField]
private float _sensitivityX = 1f, _sensitivityY = 1f;
void Update()
{
HandleLookX();
HandleLookY();
}
private void HandleLookX()
{
float mouseX = Input.GetAxis("Mouse X");
Vector3 rotation = player.transform.localEulerAngles;
rotation.y += mouseX * _sensitivityX;
player.transform.localEulerAngles = rotation;
}
private void HandleLookY()
{
float mouseY = Input.GetAxis("Mouse Y");
Vector3 rotation = transform.localEulerAngles;
rotation.x += mouseY * _sensitivityY;
rotation.x = (rotation.x > 180) ? rotation.x - 360 : rotation.x;
rotation.x = Mathf.Clamp(rotation.x, -70, 60);
transform.localEulerAngles = rotation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment