// 該程式請套用在 Main Camera 上
using UnityEngine;
using System.Collections;
public class MyCamera : MonoBehaviour {
public Transform target; // 要觀看的目標,請從外部拉進來
float temp;
bool sw = false;
void Update(){
if(Input.touchCount >= 2){
float temp2 = Vector2.Distance (Input.GetTouch (0).position, Input.GetTouch (1).position);
float cameraScale = temp2 - temp;
temp = temp2;
if(sw){
transform.localPosition = Vector3.MoveTowards (transform.position, target.position, cameraScale * Time.deltaTime / 2);
}
sw = true;
}else{
sw = false;
}
}
}
全站熱搜
留言列表