I can't zoom by pinching in the running App but i can in Unity Remote 5
Hello, I have a problem when zooming by pinching the iphone screen in the app, it doesn't zoom. Whereas when i connect my iphone via usb and use the Unity Remote to test it, it zooms by pinching the iphone screen. So i will like to know why when i build and run my App in Iphone i can't zoom by pinching. The script i will upload is the script which allows to zoom by pinching the screen. This script is attached to the Main Camera. I have to say that i also have an script that allows to rotate the 3d object by touching with just one finger, and it works well in Unity Remote and in the running App. This rotating script is attached to the 3d Object. The rotating script is programmed in Java and the zooming one is by C#; i don't know if that is relevant or can be related to the problem. Also the app is for google cardboard so i used the SDK in the project and then build it as iOS. Maybe the fact the screen is splited to use it in the Cardboard can be related to not zooming.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ZoomByTouch : MonoBehaviour
{
public float perspectiveZoomSpeed = 0.05f; // The rate of change of the field of view in perspective mode.
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;
// Otherwise change the field of view based on the change in distance between the touches.
GetComponent<Camera>().fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;
// Clamp the field of view to make sure it's between 0 and 180.
GetComponent<Camera>().fieldOfView = Mathf.Clamp(GetComponent<Camera>().fieldOfView, 0.1f, 179.9f);
}
}
}
Your answer
Follow this Question
Related Questions
zoom and pan 0 Answers
Is DateTime working on iOS? 0 Answers
How to add a Minimum and Maximum to pinch zoom touch script 2 Answers
Unity IAP Help! 0 Answers
Custom Shader IOS Build 0 Answers