Advertisement
Guest User

Untitled

a guest
Dec 10th, 2014
228
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GameControls : MonoBehaviour {
  5.  
  6.     public GameObject camera;
  7.  
  8.     Vector3 CurrentPos;
  9.     Vector3 NewPos;
  10.     public float panSpeed = 5f;
  11.  
  12.     float CurrentZoom= 10;
  13.     public float NewZoom;
  14.    
  15.     Vector2 currTouch1;
  16.     Vector2 currTouch2;
  17.     Vector2 lastTouch1;
  18.     Vector2 lastTouch2;
  19.    
  20.     float lastTouchDistance;
  21.     float currTouchDistance;
  22.  
  23.     void Start(){
  24.         CurrentPos = transform.position;
  25.         NewPos = transform.position;
  26.     }
  27.    
  28.  
  29.     void FixedUpdate(){
  30.         CurrentPos = Vector3.Lerp (CurrentPos, NewPos, 0.1f);
  31.         transform.position = CurrentPos;
  32.  
  33.         CurrentZoom = Mathf.Lerp (CurrentZoom, NewZoom, 0.1f);
  34.         camera.transform.localPosition = new Vector3 (0, 0, -CurrentZoom);
  35.  
  36.     }
  37.  
  38.     void Update(){
  39.         if (Input.touchCount == 1) {
  40.             if (Input.GetTouch (0).phase.Equals (TouchPhase.Moved)) {
  41.                 NewPos += new Vector3 (
  42.                     -Input.GetTouch(0).deltaPosition.x/Screen.width*panSpeed,
  43.                     0,
  44.                     -Input.GetTouch(0).deltaPosition.y/Screen.height*panSpeed
  45.                     ); 
  46.                 Debug.Log(Input.GetTouch(0).deltaPosition.x/Screen.width);
  47.             }
  48.         }
  49.  
  50.         if (Input.touchCount == 2){
  51.             currTouch1 = Input.GetTouch(0).position;
  52.             lastTouch1 = currTouch1 - Input.GetTouch(0).deltaPosition;
  53.  
  54.             currTouch2 = Input.GetTouch(1).position;
  55.             lastTouch2 = currTouch2 - Input.GetTouch(1).deltaPosition;
  56.  
  57.             currTouchDistance = Vector2.Distance(currTouch1, currTouch2);
  58.             lastTouchDistance = Vector2.Distance(lastTouch1, lastTouch2);
  59.  
  60.             float zoomFactor = (lastTouchDistance - currTouchDistance)*CurrentZoom/2*0.01f;
  61.             NewZoom += zoomFactor;
  62.  
  63.             if(NewZoom < 1){NewZoom = 1;}
  64.             if(NewZoom > 30){NewZoom = 30;}
  65.            
  66.  
  67.             Debug.Log (zoomFactor);
  68.            
  69.         }
  70.     }
  71. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement