Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class CameraControl : MonoBehaviour
- {
- public Transform target;
- public Vector3 offset;
- public float sensitivity = 3; // чувствительность мышки
- public float limit = 80; // ограничение вращения по Y
- public float zoom = 0.25f; // чувствительность при увеличении, колесиком мышки
- public float zoomMax = 10; // макс. увеличение
- public float zoomMin = 3; // мин. увеличение
- private float X, Y;
- public bool may;
- void Start()
- {
- limit = Mathf.Abs(limit);
- if (limit > 90) limit = 90;
- offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax) / 2);
- transform.position = target.position + offset;
- }
- void Update()
- {
- float length = 0;
- float tempLength;
- float x1 = 0;
- float x2;
- float y1 = 0;
- float y2;
- bool b = false;
- switch (Input.touchCount)
- {
- case 1:
- if (may)
- {
- if (!b)
- {
- x1 = Input.GetTouch(0).position.x;
- y1 = Input.GetTouch(0).position.y;
- b = true;
- }
- x2 = x1;
- x1 = Input.GetTouch(0).position.x;
- y2 = y1;
- y1 = Input.GetTouch(0).position.y;
- X = transform.localEulerAngles.y * sensitivity * (x2 - x1);
- Y += (y2 - y1) * sensitivity;
- print(y2-y1);
- Y = Mathf.Clamp(Y, -limit, limit);
- }
- break;
- case 2:
- if (may)
- {
- tempLength = length;
- length = (Input.GetTouch(0).position - Input.GetTouch(1).position).magnitude;
- offset.z -= length - tempLength;
- offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
- }
- break;
- }
- transform.localEulerAngles = new Vector3(-Y, X, 0);
- transform.position = transform.localRotation * offset + target.position;
- }
- public void May(bool b) => may = b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement