- Home /
Make Table_Transform as public and assign that in inspector window.
Pinch not working
Hi, i have code for scale my objects using pinch. But it's not working, can anyone tell me please?
using UnityEngine;
using System.Collections;
public class Zoom_Button : MonoBehaviour
{
private Transform Table_Transform = null;
public float scaleFactor = 0.5f; // The rate of change of the scale
public float minScale = 0.6f;
public float maxScale = 2.0f;
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;
Table_Transform.localScale += new Vector3(deltaMagnitudeDiff * scaleFactor, deltaMagnitudeDiff * scaleFactor, deltaMagnitudeDiff * scaleFactor);
float Table_X, Table_Y, Table_Z;
Table_X = Mathf.Clamp(Table_Transform.localScale.x, minScale, maxScale);
Table_Y = Mathf.Clamp(Table_Transform.localScale.y, minScale, maxScale);
Table_Z = Mathf.Clamp(Table_Transform.localScale.z, minScale, maxScale);
Table_Transform.localScale = new Vector3(Table_X, Table_Y, Table_Z);
}
}
}
This is the code. Here it didn't show any errors.
-Prasanna
@yashpal, actually am using webcamtexture for my project, so if am use to pinch the camera my whole camera(view) is zoo$$anonymous$$g. But i want to zoom only the objects, that's why i choose this way to zoom.
Answer by HarshadK · Dec 02, 2014 at 06:46 AM
You need to assign a transform to your Table_Transform variable otherwise it will be null always. Just assign your transform of your intended object in Start() to your Table_Transform variable.
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Accurate Pinch Zoom 1 Answer
Math behind Unity camera model 0 Answers
Blender and Unity Camera Setup 1 Answer