Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class orthoCameraMan : MonoBehaviour {
- public Transform target;
- public Vector3 offset;
- public float minSize;
- public float maxSize;
- public float lowClamp;
- public float highClamp;
- public float dragSpeed;
- public float camFocusSpeed;
- public float camFocusTurnSpeed;
- private float cameraMovement;
- private RaycastHit hit;
- private int loopCount;
- void Start () {
- }
- void LateUpdate () {
- if (target != null) {
- transform.LookAt(target);
- transform.position = target.position + offset;
- }
- //pinch and pull to zoom the camera
- if (Input.touchCount == 2) {
- target = null; //unset any camera targeting
- Touch firstFinger = Input.GetTouch(0);
- Touch secondFinger = Input.GetTouch(1);
- float touchDistance = Vector2.Distance(firstFinger.position, secondFinger.position);
- if (firstFinger.phase == TouchPhase.Moved || secondFinger.phase == TouchPhase.Moved) {
- float lastDistance = Vector2.Distance(firstFinger.position - firstFinger.deltaPosition, secondFinger.position - secondFinger.deltaPosition);
- float moveDistance = Mathf.Clamp(touchDistance - lastDistance, lowClamp, highClamp);
- Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize - moveDistance, minSize, maxSize);
- }
- }
- if (Input.touchCount == 1 &&
- Input.GetTouch(0).tapCount == 2 &&
- rayAtTouch(out hit, Input.GetTouch(0).position) &&
- hit.collider.gameObject.layer == (int)Layers.Index.playerActorLayer)
- {
- target = hit.collider.gameObject.transform;
- StartCoroutine(repositionCam());
- }
- }
- public void dragCamera (Vector3 scrollDist) {
- Vector3 normalizeScrollDist = new Vector3(scrollDist.x * Time.deltaTime * dragSpeed,
- 0, scrollDist.z * Time.deltaTime * dragSpeed);
- transform.position += normalizeScrollDist;
- }
- IEnumerator repositionCam () {
- while (cameraMovement < 1) {
- cameraMovement += camFocusSpeed * Time.deltaTime;
- transform.position = Vector3.Lerp(transform.position, transform.position + offset, cameraMovement);
- yield return null;
- }
- }
- bool rayAtTouch (out RaycastHit rayHit, Vector3 touchLoc) {
- Ray ray = Camera.main.ScreenPointToRay(touchLoc);
- return Physics.Raycast(ray, out rayHit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement