Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraControl : MonoBehaviour
  5. {
  6. public Transform target;
  7. public Vector3 offset;
  8.  
  9. public float sensitivity = 3; // чувствительность мышки
  10. public float limit = 80; // ограничение вращения по Y
  11.  
  12. public float zoom = 0.25f; // чувствительность при увеличении, колесиком мышки
  13. public float zoomMax = 10; // макс. увеличение
  14. public float zoomMin = 3; // мин. увеличение
  15.  
  16. private float X, Y;
  17.  
  18. public bool may;
  19.  
  20. void Start()
  21. {
  22. limit = Mathf.Abs(limit);
  23. if (limit > 90) limit = 90;
  24.  
  25. offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax) / 2);
  26. transform.position = target.position + offset;
  27. }
  28.  
  29. void Update()
  30. {
  31. float length = 0;
  32. float tempLength;
  33.  
  34. float x1 = 0;
  35. float x2;
  36.  
  37. float y1 = 0;
  38. float y2;
  39.  
  40. bool b = false;
  41.  
  42. switch (Input.touchCount)
  43. {
  44. case 1:
  45. if (may)
  46. {
  47. if (!b)
  48. {
  49. x1 = Input.GetTouch(0).position.x;
  50. y1 = Input.GetTouch(0).position.y;
  51. b = true;
  52. }
  53.  
  54. x2 = x1;
  55. x1 = Input.GetTouch(0).position.x;
  56.  
  57. y2 = y1;
  58. y1 = Input.GetTouch(0).position.y;
  59.  
  60. X = transform.localEulerAngles.y * sensitivity * (x2 - x1);
  61. Y += (y2 - y1) * sensitivity;
  62.  
  63. print(y2-y1);
  64.  
  65. Y = Mathf.Clamp(Y, -limit, limit);
  66. }
  67. break;
  68. case 2:
  69. if (may)
  70. {
  71. tempLength = length;
  72. length = (Input.GetTouch(0).position - Input.GetTouch(1).position).magnitude;
  73.  
  74. offset.z -= length - tempLength;
  75.  
  76. offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
  77. }
  78. break;
  79. }
  80.  
  81. transform.localEulerAngles = new Vector3(-Y, X, 0);
  82. transform.position = transform.localRotation * offset + target.position;
  83. }
  84.  
  85. public void May(bool b) => may = b;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement