Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class GameControls : MonoBehaviour {
- public GameObject camera;
- Vector3 CurrentPos;
- Vector3 NewPos;
- public float panSpeed = 5f;
- float CurrentZoom= 10;
- public float NewZoom;
- Vector2 currTouch1;
- Vector2 currTouch2;
- Vector2 lastTouch1;
- Vector2 lastTouch2;
- float lastTouchDistance;
- float currTouchDistance;
- void Start(){
- CurrentPos = transform.position;
- NewPos = transform.position;
- }
- void FixedUpdate(){
- CurrentPos = Vector3.Lerp (CurrentPos, NewPos, 0.1f);
- transform.position = CurrentPos;
- CurrentZoom = Mathf.Lerp (CurrentZoom, NewZoom, 0.1f);
- camera.transform.localPosition = new Vector3 (0, 0, -CurrentZoom);
- }
- void Update(){
- if (Input.touchCount == 1) {
- if (Input.GetTouch (0).phase.Equals (TouchPhase.Moved)) {
- NewPos += new Vector3 (
- -Input.GetTouch(0).deltaPosition.x/Screen.width*panSpeed,
- 0,
- -Input.GetTouch(0).deltaPosition.y/Screen.height*panSpeed
- );
- Debug.Log(Input.GetTouch(0).deltaPosition.x/Screen.width);
- }
- }
- if (Input.touchCount == 2){
- currTouch1 = Input.GetTouch(0).position;
- lastTouch1 = currTouch1 - Input.GetTouch(0).deltaPosition;
- currTouch2 = Input.GetTouch(1).position;
- lastTouch2 = currTouch2 - Input.GetTouch(1).deltaPosition;
- currTouchDistance = Vector2.Distance(currTouch1, currTouch2);
- lastTouchDistance = Vector2.Distance(lastTouch1, lastTouch2);
- float zoomFactor = (lastTouchDistance - currTouchDistance)*CurrentZoom/2*0.01f;
- NewZoom += zoomFactor;
- if(NewZoom < 1){NewZoom = 1;}
- if(NewZoom > 30){NewZoom = 30;}
- Debug.Log (zoomFactor);
- }
- }
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement