Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Problem with Input.touchCount == 1

$
0
0
Howdy Everyone! I have an orthographic camera facing z negative at positive z = 20. I want the player to pan the camera with one finger and zoom the camera when they pinch. So far I have the pinch function working but I can't figure out why my pan function broken. Can anyone tell me what I'm doing wrong? #pragma strict import UnityEngine; import System.Collections; var speed : int = 4; var selectedCamera : Camera; var MINSCALE : float = 2.0F; var MAXSCALE : float = 5.0F; var varianceInDistances : float = 5.0F; private var touchDelta : float = 0.0F; private var prevDist : Vector2; private var curDist : Vector2; private var startAngleBetweenTouches : float = 0.0F; private var midPoint : Vector2; function Update () { if (Input.touchCount == 1) // { var touchDeltaPosition : Vector2 = Input.GetTouch(0).deltaPosition; selectedCamera.transform.parent.transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0); } // droid zoom controls if (Input.touchCount == 2) // && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved) { midPoint = Vector2(((Input.GetTouch(0).position.x + Input.GetTouch(1).position.x)/2), ((Input.GetTouch(0).position.y - Input.GetTouch(1).position.y)/2)); //store midpoint from first touches 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; if ((touchDelta < 0)) // { selectedCamera.orthographicSize = Mathf.Clamp(selectedCamera.orthographicSize + (1 * speed),2,90); } if ((touchDelta > 0)) { selectedCamera.orthographicSize = Mathf.Clamp(selectedCamera.orthographicSize - (1 * speed),2,90); } } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>