Пример #1
0
    void CameraHandler()
    {
        if (editMode)
        {
            // Does the main camera exist?
            if (Camera.main != null)
            {
                // Get the world delta of all the fingers
                Vector3 worldDelta = LeanTouch.GetDeltaWorldPosition(10f); // Distance doesn't matter with an orthographic camera

                Camera.main.transform.position -= worldDelta;

                // Make sure the pinch scale is valid
                if (LeanTouch.PinchScale > 0.0f)
                {
                    // Store the old FOV in a temp variable
                    float cameraDistance = Camera.main.transform.position.z;

                    // Scale the FOV based on the pinch scale
                    cameraDistance /= LeanTouch.PinchScale;

                    // Clamp the FOV to out min/max values
                    cameraDistance = Mathf.Clamp(cameraDistance, maxDistance, minDistance);

                    // Set the new FOV
                    Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, cameraDistance);
                }
            }
        }
    }