// Update is called once per frame void Update() { prevMouseX = mouseX; prevMouseY = mouseY; mouseX = Input.mousePosition.x; mouseY = Input.mousePosition.y; // Count down scrollTimer to decide whether tapping or dragging if (!isScrolling && Input.GetMouseButton(0)) { isScrollingTimer -= Time.deltaTime; if (isScrollingTimer <= 0.0f) { isScrolling = true; } } // If a tap, find what was clicked on and act on it if (Input.GetMouseButtonUp(0)) { // If player wasn't scrolling and able to click if (!isScrolling && canClick) { if (textShowing) { DestroyText(); } else { ClickAction(); } } else { } // Reset scrolling isScrollingTimer = scrollTimerVal; isScrolling = false; } // Zooming if (canScroll && canClick) { // Windows zooming if (Input.GetAxis("Mouse ScrollWheel") > 0) { // Zoom in cameraController.Zoom(-1.0f); uiController.UpdateUI(); } if (Input.GetAxis("Mouse ScrollWheel") < 0) { // Zoom out cameraController.Zoom(1.0f); uiController.UpdateUI(); } // Mobile zooming // 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; cameraController.Zoom(deltaMagnitudeDiff * 0.1f); } } // Controls camera scrolling if (isScrolling && canScroll) { var direction = new Vector2(prevMouseX - mouseX, prevMouseY - mouseY); cameraController.Scroll(direction); } if (clickTimer > 0.0f) { clickTimer -= Time.deltaTime; if (clickTimer <= 0.0f) { EnableClicking(); } } }