//左手手指
Vector2 oldPos1;
//右手手指
Vector2 oldPos2;
// Use this for initialization
void Start() {
void Update() {
if(Input.touchCount == 2){
if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
{
//现在手指所在坐标
Vector2 temPos1 = Input.GetTouch(0).position;
Vector2 temPos2 = Input.GetTouch(1).position;
{
//放大
float oldScale = transform.localScale.x;
float newScale = oldScale * 1.025f;
transform.localScale = new Vector3(newScale, newScale, newScale);
}
else
{
//缩小
float oldScale = transform.localScale.x;
float newScale = oldScale / 1.025f;
transform.localScale = new Vector3(newScale, newScale, newScale);
}
oldPos1 = temPos1;
oldPos2 = temPos2;
}
}
}
{
float length1 = Mathf.Sqrt((oP1.x - oP2.x) * (oP1.x - oP2.x) + (oP1.y - oP2.y) * (oP1.y - oP2.y));
float length2 = Mathf.Sqrt((nP1.x - nP2.x) * (nP1.x - nP2.x) + (nP1.y - nP2.y) * (nP1.y - nP2.y));
if (length1 < length2) {
return true;
}
else { return false; }
}
}