Advertisement
RealiteeeyyyyTV

Untitled

Jan 7th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Dynamic : MonoBehaviour
  5. {
  6.  
  7. private const float Y_ANGLE_MIN = -50.0f;
  8. private const float Y_ANGLE_MAX = 50.0f;
  9.  
  10. public Transform lookAt;
  11. public Transform camTransform;
  12.  
  13. private Camera cam;
  14.  
  15. private float distance = 10.0f;
  16. private float currentX = 0.0f;
  17. private float currentY = 0.0f;
  18. private float sensivityX = 4.0f;
  19. private float sensivityY = 1.0f;
  20.  
  21. private void Start()
  22. {
  23. camTransform = transform;
  24. cam = Camera.main;
  25. }
  26.  
  27. private void Update()
  28. {
  29. currentX += Input.GetAxis("Mouse X");
  30. currentY += Input.GetAxis("Mouse Y");
  31.  
  32. currentY = Mathf.Clamp(currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
  33. }
  34.  
  35. private void LateUpdate()
  36. {
  37. Vector3 dir = new Vector3(0, 0, -distance);
  38. Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
  39. camTransform.position = lookAt.position + rotation * dir;
  40. camTransform.LookAt(lookAt.position);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement