Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MouseLook : MonoBehaviour {
  6.  
  7. private Camera cam;
  8. float mouseX = 0;
  9. float mouseY = 0;
  10. float mouseSensitivity = 1;
  11.  
  12. float camRotX = 0;
  13. // Use this for initialization
  14. void Start () {
  15. cam = Camera.main;
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update () {
  20. GetMouseLook();
  21.  
  22. }
  23. void GetMouseLook()
  24. {
  25. mouseX = Input.GetAxis("Mouse X");
  26. mouseY = Input.GetAxis("Mouse Y");
  27.  
  28. float rotAmountX = mouseX * mouseSensitivity;
  29. float rotAmountY = mouseY * mouseSensitivity;
  30.  
  31. Vector3 targetRot = transform.rotation.eulerAngles;
  32. targetRot.x += rotAmountY;
  33. targetRot.y += rotAmountX;
  34.  
  35. camRotX -= rotAmountY;
  36. if(camRotX > 30)
  37. {
  38. camRotX = 30;
  39. }
  40. else if(camRotX < -30)
  41. {
  42. camRotX = -30;
  43. }
  44. transform.rotation = Quaternion.Euler(0, targetRot.y, 0);
  45.  
  46. cam.transform.localRotation = Quaternion.Euler(camRotX, 0, 0);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement