如何在Android Unity3D手机中减慢放大和缩小速度

时间:2017-08-19 18:00:38

标签: c# android unity3d

以下是我正在使用的代码

 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的值,并尝试将其设为负值,但放大和缩小速度仍然太快。我希望速度慢很多。

1 个答案:

答案 0 :(得分:0)

我是个白痴。我一直在尝试更改c#代码中的zoomSpeed值。在Unity中,我在主摄像头组件中添加了c#脚本。有缩放速度,这是需要改变的价值。这是如此简单,但我完全是初学者,我不知道。