Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MouseLook : MonoBehaviour {
- private Camera cam;
- float mouseX = 0;
- float mouseY = 0;
- float mouseSensitivity = 1;
- float camRotX = 0;
- // Use this for initialization
- void Start () {
- cam = Camera.main;
- }
- // Update is called once per frame
- void Update () {
- GetMouseLook();
- }
- void GetMouseLook()
- {
- mouseX = Input.GetAxis("Mouse X");
- mouseY = Input.GetAxis("Mouse Y");
- float rotAmountX = mouseX * mouseSensitivity;
- float rotAmountY = mouseY * mouseSensitivity;
- Vector3 targetRot = transform.rotation.eulerAngles;
- targetRot.x += rotAmountY;
- targetRot.y += rotAmountX;
- camRotX -= rotAmountY;
- if(camRotX > 30)
- {
- camRotX = 30;
- }
- else if(camRotX < -30)
- {
- camRotX = -30;
- }
- transform.rotation = Quaternion.Euler(0, targetRot.y, 0);
- cam.transform.localRotation = Quaternion.Euler(camRotX, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement