[英]How to slowdown zoom in and zoom out speed in Android Unity3D for mobile phones
Here is the code I am using 这是我正在使用的代码
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);
}
}
}
I tried adding zeroes to value of zoomSpeed and also tried making it negative but the zoom in and out speed is still too fast. 我尝试将零添加到zoomSpeed的值,还尝试使其设为负数,但放大和缩小速度仍然过快。 I want the speed to be a lot slower.
我希望速度要慢很多。
I am such an idiot. 我真是个白痴。 I have been trying to change the zoomSpeed value in the c# code.
我一直试图在c#代码中更改zoomSpeed值。 In Unity, in the main camera component where I added the c# script.
在Unity中,在主要的相机组件中添加了c#脚本。 There is Zoom Speed and that's the value that needs to be change.
有“缩放速度”,这是需要更改的值。 It was so simple but I am total beginner that I didn't know that.
太简单了,但是我完全是个初学者,我不知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.