void TouchInput() { if (!canMove) { return; } // Zoom with 2 fingers if (Input.touchCount == 2) { Touch touch1 = Input.GetTouch(0); Touch touch2 = Input.GetTouch(1); firstTouchVec = touch2.position - touch1.position; // Vector between first touch points // Get the magnitude of vector that is formed in the points of 2 touch inputs if ((touch1.phase == TouchPhase.Began) || touch2.phase == TouchPhase.Began) { firstMagnitude = firstTouchVec.magnitude; firstMagnitude /= zoomDivisor; } curMagnitude = firstTouchVec.magnitude - firstMagnitude; // Make value more sensible curMagnitude /= zoomDivisor; // Check whether to zoom in or out if (firstMagnitude > (firstTouchVec.magnitude / zoomDivisor)) { zoomMultiplier += curMagnitude / zoomSpeed; } else { zoomMultiplier -= curMagnitude / zoomSpeed; } zoomMultiplier = Mathf.Clamp(zoomMultiplier, minZoomMult, maxZoomMult); //debugText.text = firstMagnitude.ToString() + "|" + (firstTouchVec).ToString(); mainCam.orthographicSize = initialOrtoSize * zoomMultiplier; if (touch1.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Ended) { StartCoroutine(CooldownCoroutine()); } } // Move the map with 1 finger if (Input.touchCount == 1) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { touchStartPos = mainCam.ScreenToWorldPoint(touch.position); touchTimer = 0; } if (touch.phase == TouchPhase.Ended && touchTimer < 0.1f && gpsScript.InMapArea) { Vector3 newCamPos = gpsScript.GetUserIndicatorImg().transform.position; newCamPos.z = -10f; mainCam.transform.position = newCamPos; StartCoroutine(ResetPosCooldownRoutine()); return; } touchDirection = touchStartPos - mainCam.ScreenToWorldPoint(touch.position); desiredPosition += touchDirection * scrollSpeed; desiredPosition.z = -10f; // if(touchDirection.magnitude > 70f) // { // desiredPosition.x += touchDirection.x; // desiredPosition.y += touchDirection.y; // desiredPosition /= 20f; // desiredPosition.z = -10f; // } // debugText.text = touchDirection.magnitude.ToString(); //mainCam.transform.Translate(touchDirection.x * (speed*0.1f) * Time.deltaTime, touchDirection.y * (speed*0.1f) * Time.deltaTime, 0f); touchTimer += Time.deltaTime; } // Test input for moving the camera, so the user can scroll the map #region TestPanning // Input for moving the camera, so the user can scroll the map // if(Input.touchCount == 1) // { // /* // Vector3 temp = swipe.SwipeDelta; // // Adjust the value to make the camera move slower or quicker // temp *= swipeValue; // desiredPosition -= temp; // desiredPosition.z = -10f; // */ // // float x = ss.HorizontalMoveDistance(); // // float y = ss.VerticalMoveDistance(); // float x = ss.DistVec().x; // float y = ss.DistVec().y; // debugText.text = x.ToString() + "|" + y.ToString(); // desiredPosition = new Vector3(x, y, -10f); // } #endregion }