public void OnPointerDown(PointerEventData eventData) { if ((DateTime.Now - lastClickTime).TotalMilliseconds < 500) { GameLogicHandler.onRightClick(eventData.position); } lastClickTime = DateTime.Now; }
public void Update() { float widthBoarder = Screen.width * 0.10f; float heightBoarder = Screen.height * 0.10f; int validTouchCount = 0; if (Input.touchCount > 0) { for (int i = 0; i < Input.touchCount; i++) { Touch touch = Input.GetTouch(i); lastTouch = touch; if (touch.position.x > widthBoarder && touch.position.x < Screen.width - widthBoarder && touch.position.y > heightBoarder) { validTouchCount++; if (isDraging && lastPosition != null) { UpdateVirtualAxes(new Vector2(touch.position.x, touch.position.y) - lastPosition); } pressedTime += Time.deltaTime; if (pressedTime > 0.1f) { isDraging = true; lastPosition = touch.position; } if (isPressed == false) { isPressed = true; } lastPosition = touch.position; } } } if (validTouchCount <= 0) { if (isPressed && pressedTime < 0.3f) { if ((DateTime.Now - lastClickTime).TotalMilliseconds < 500) { GameLogicHandler.onRightClick(lastTouch.position); } lastClickTime = DateTime.Now; } if (isPressed) { UpdateVirtualAxes(Vector3.zero); pressedTime = 0; isDraging = false; isPressed = false; } } }