Hi guys, i did this script (mixing different things i found on the various forum) and it works fantastic.
My only problem is that i need to add a min scale to the gameobject with this script attacked because without it my gameobject goes “negative” 
function Update ()
{
if ( Input.touchCount == 2 ) {
var touch1 : iPhoneTouch = iPhoneInput.GetTouch( 0 );
var touch2 : iPhoneTouch = iPhoneInput.GetTouch( 1 );
// Find out how the touches have moved relative to eachother:
var curDist : Vector2 = touch1.position - touch2.position;
var prevDist : Vector2 = (touch1.position - touch1.positionDelta) - (touch2.position - touch2.positionDelta);
var touchDelta : float = curDist.magnitude - prevDist.magnitude;
// transform the GameObject Scale along the local coordinations
transform.localScale += Vector3(touchDelta0.01,touchDelta0.01,touchDelta*0.01 );
}
}
Any help would be really welcome.
try this.
var MINSCALE : Float; //Define the min scale as a float for example 0.5;
if (transform.localScale.Magnitude > MINSCALE) // then compare and execute the scaling
transform.localScale += Vector3(touchDelta0.01,touchDelta0.01,touchDelta *0.01 );
Hi Afisicos! Thank you so much for that!
It works but it remains stuck in the minscale…
i tried other ideas but it always stays frozen in the minscale.
Anyway is a good start!
Iguana
No problem,
Have you tried ‘<’ instead ‘>’ ?
I don’t know why it doesn’t works if it isn’t the problem 
Ah Ok, I understand the frozen state.
Is because when the scale is exactly in the limit. ( f.e. scale = 0.501 and MINSCALE = 0.5)
if you give him a smaller scale, later the scale is 0.5 that is EQUAL to the MINSCALE… then the if won’t work anytime more.
try this :
var MINSCALE : Float;
var MAXSCALE : Float;
if ((transform.localScale.Magnitude > MINSCALE)(touchDelta >= 0)) transform.localScale += Vector3(touchDelta0.01,touchDelta0.01,touchDelta *0.01 );
if ((transform.localScale.Magnitude < MAXSCALE)(touchDelta < 0)) transform.localScale += Vector3(touchDelta0.01,touchDelta0.01,touchDelta *0.01 );
Hola Hombre! Thank you so much for your help, its still stuck but in the opposite direction (zoom in)…but your code look great and now i’m going to read it carefully to see where is the problem.
It is so difficult to solve this problem, i thought was easier 
DONE! (almost)
its a bit random (if i zoom out too fast the model still goes “negative” but now it works.
Here is the code:
function Update ()
{
if ( Input.touchCount == 2 ) {
var touch1 : iPhoneTouch = iPhoneInput.GetTouch( 0 );
var touch2 : iPhoneTouch = iPhoneInput.GetTouch( 1 );
// Find out how the touches have moved relative to eachother:
var curDist : Vector2 = touch1.position - touch2.position;
var prevDist : Vector2 = (touch1.position - touch1.positionDelta) - (touch2.position - touch2.positionDelta);
var touchDelta : float = curDist.magnitude - prevDist.magnitude;
// translate along local coordinate space
var MINSCALE : float = 1.5;
var MAXSCALE : float = 15;
if ((transform.localScale.magnitude > MINSCALE)(touchDelta <= 1)) transform.localScale += Vector3(touchDelta0.01,touchDelta0.01,touchDelta *0.01 );
if ((transform.localScale.magnitude < MAXSCALE)(touchDelta > 1)) transform.localScale += Vector3(touchDelta0.01,touchDelta0.01,touchDelta *0.01 );
}
}
Thank you so much for your help, you saved me!
iguana
It is working perfectly???
I want to know
and later I want to try it on an aplication in my android mobile. I’m making a little sport game and I want to use your zoom code 
It works great, i just have to fix the issue (if you zoom out too fast it goes negative) but in general is a very clean and fast solution for pinch zoom a gameObject.
I’m happy if you use it, its also your code! 
Have a great day man!
Iguana
thanks too. I like to help when I can.
Tell me how is you aplication when you finish it.
grettings
][quote=“iguana_02, post:1, topic: 450105, username:iguana_02”]
…
var touch1 : iPhoneTouch = iPhoneInput.GetTouch( 0 );
var touch2 : iPhoneTouch = iPhoneInput.GetTouch( 1 );
// Find out how the touches have moved relative to eachother:
var curDist : Vector2 = touch1.position - touch2.position;
var prevDist : Vector2 = (touch1.position - touch1.positionDelta) - (touch2.position - touch2.positionDelta);
…
[/quote]
Hi
Unfortunately this script is not working with UnityPro 3.4 for Android devices. >iPhoneInput.GetTouch and touch1.positionDelta prompts some errors.
Instead of “iPhoneInput.GetTouch” > “Input.GetTouch” should be used for ALL mobile devices. And “positionDelta” seems not to be avaiable any more in this combination… ?
But could imagine, that one of you coder chiefs could modify this, to control smoothly the field of view of the camera with the “pinch” guesture. Like one of the most common multitouch features at all is providing.
I guess, this would be of a greater public interest to all of non coder freaks…
Thanks for that help
I was tired of looking around on these forums for this code example…
i converted it to android. I’m not sure what the local.scale does, i think it scales all transforms, but im not sure… but it works.
using UnityEngine;
using System.Collections;
public class CameraZoomPinch : MonoBehaviour
{
public int speed = 4; //for some reason only int values affected zoom speeds, float didnt work
public Camera selectedCamera;
//i believe using an inspector assigned object variable is easier on cpu than using getobject methods
public float MINSCALE = 2.0F;
public float MAXSCALE = 5.0F;
public float minPinchSpeed = 5.0F;
public float varianceInDistances = 5.0F;
//above variable : to try to account for a little bit of error in distrance and also if you intend to use two finger gestures
private float touchDelta = 0.0F;
private Vector2 prevDist = new Vector2(0,0);
private Vector2 curDist = new Vector2(0,0);
private float speedTouch0 = 0.0F;
private float speedTouch1 = 0.0F;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.touchCount == 2 Input.GetTouch(0).phase == TouchPhase.Moved Input.GetTouch(1).phase == TouchPhase.Moved)
{
curDist = Input.GetTouch(0).position - Input.GetTouch(1).position; //current distance between finger touches
prevDist = ((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition)); //difference in previous locations using delta positions
touchDelta = curDist.magnitude - prevDist.magnitude;
speedTouch0 = Input.GetTouch(0).deltaPosition.magnitude / Input.GetTouch(0).deltaTime;
speedTouch1 = Input.GetTouch(1).deltaPosition.magnitude / Input.GetTouch(1).deltaTime;
if ((touchDelta + varianceInDistances <= 1) (speedTouch0 > minPinchSpeed) (speedTouch1 > minPinchSpeed))
{
selectedCamera.fieldOfView = Mathf.Clamp(selectedCamera.fieldOfView + (1 * speed),15,90);
}
if ((touchDelta +varianceInDistances > 1) (speedTouch0 > minPinchSpeed) (speedTouch1 > minPinchSpeed))
{
selectedCamera.fieldOfView = Mathf.Clamp(selectedCamera.fieldOfView - (1 * speed),15,90);
}
}
}
}