Guest User

Untitled

a guest
Nov 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6.  
  7. public class followView : MonoBehaviour {
  8. bool mouseDown = false;
  9. float mouseX;
  10. float mouseY;
  11.  
  12. Camera mainCamera;
  13.  
  14. void Start () {
  15. mainCamera = GetComponent<Camera>();
  16. }
  17.  
  18. void Update () {
  19.  
  20. if(Input.GetMouseButtonDown(0) && !mouseDown )
  21. {
  22. mouseDown = true;
  23.  
  24. mouseX = Input.mousePosition.x;
  25. mouseY = Input.mousePosition.y;
  26. }
  27. else if(Input.GetMouseButtonUp(0) && mouseDown)
  28. {
  29. mouseDown = false;
  30. }
  31. }
  32.  
  33. void LateUpdate()
  34. {
  35. if(mouseDown)
  36. {
  37. float mouseXStop = Input.mousePosition.x;
  38. float mouseYStop = Input.mousePosition.y;
  39. float deltaX = mouseXStop - mouseX;
  40. float deltaY = mouseYStop - mouseY;
  41. float centerXNew = Screen.width / 2 + deltaX;
  42. float centerYNew = Screen.height / 2 + deltaY;
  43.  
  44. Vector3 Gaze = mainCamera.ScreenToWorldPoint(new Vector3(centerXNew, centerYNew, mainCamera.nearClipPlane));
  45. transform.LookAt(Gaze);
  46. mouseX = mouseXStop;
  47. mouseY = mouseYStop;
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment