Just to help the body.
Using Unityengine;
Using System.Collections;
Using System.IO;
public class Hehe:monobehaviour
{
Private Touch oldTouch1; Last touch point 1 (finger 1)
Private Touch OLDTOUCH2; Last touch point 2 (finger 2)
void Start ()
{
}
void Update ()
{
No touch
if (input.touchcount <= 0)
{
Return
}
Single touch, horizontal up/down rotation
if (1 = = Input.touchcount)
{
Touch touch = Input.gettouch (0);
Vector2 deltapos = touch.deltaposition;
Transform. Rotate (Vector3.down * deltapos.x, Space.world);
Transform. Rotate (Vector3.right * deltapos.y, Space.world);
}
Multi-touch, zoom-in and zoom out
Touch newTouch1 = Input.gettouch (0);
Touch NEWTOUCH2 = Input.gettouch (1);
The 2nd just starts to touch the screen, only records, does not do the processing
if (newtouch2.phase = = Touchphase.began)
{
OLDTOUCH2 = NEWTOUCH2;
OldTouch1 = NewTouch1;
Return
}
Calculate old two-point distance and new two-point distance, zoom model, zoom model
float olddistance = vector2.distance (oldtouch1.position, oldtouch2.position);
float newdistance = vector2.distance (newtouch1.position, newtouch2.position);
Two distance difference, to indicate a magnification gesture, to reduce the gesture for negative representation
float offset = newdistance-olddistance;
Magnification factor, one pixel is calculated as 0.01 times times (100 adjustable)
float scalefactor = offset/100f;
Vector3 Localscale = Transform.localscale;
Vector3 scale = new Vector3 (localscale.x + scalefactor,
Localscale.y + Scalefactor,
Localscale.z + scalefactor);
Minimum zoom to 0.3 times times
if (scale.x > 0.3f && scale.y > 0.3f && scale.z > 0.3f)
{
Transform.localscale = scale;
}
Remember the latest touch points, the next time you use
OldTouch1 = NewTouch1;
OLDTOUCH2 = NEWTOUCH2;
}
}
Unity releases Android finger to control object scaling and rotation