以下是我正在使用的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PinchZoom : MonoBehaviour
{
public Canvas canvas; // The canvas
public float zoomSpeed = .000000000000000001f; // The rate of change
of the canvas scale factor
void Update()
{
// If there are two touches on the device...
if (Input.touchCount == 2)
{
// Store both touches.
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
// Find the position in the previous frame of each touch.
Vector2 touchZeroPrevPos = touchZero.position -
touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position -
touchOne.deltaPosition;
// Find the magnitude of the vector (the distance) between the
touches in each frame.
float prevTouchDeltaMag = (touchZeroPrevPos -
touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position -
touchOne.position).magnitude;
// Find the difference in the distances between each frame.
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
// ... change the canvas size based on the change in distance
between the touches.
canvas.scaleFactor -= deltaMagnitudeDiff * zoomSpeed;
// Make sure the canvas size never drops below 0.1
canvas.scaleFactor = Mathf.Max(canvas.scaleFactor, .7f);
}
}
}
我尝试将零添加到zoomSpeed的值,并尝试将其设为负值,但放大和缩小速度仍然太快。我希望速度慢很多。
答案 0 :(得分:0)