public void OnDrag(PointerEventData eventData) { cam = null; if (canvas.renderMode == RenderMode.ScreenSpaceCamera) { cam = canvas.worldCamera; } Vector2 position = RectTransformUtility.WorldToScreenPoint(cam, background.position); Vector2 radius = background.sizeDelta / 2; input = (eventData.position - position) / (radius * canvas.scaleFactor); FormatInput(); HandleInput(input.magnitude, input.normalized, radius, cam); handle.anchoredPosition = input * radius * handleRange; JoystickOnDragDelegate?.Invoke(); }
public virtual void OnPointerUp(PointerEventData eventData) { input = Vector2.zero; handle.anchoredPosition = Vector2.zero; JoystickOnDragDelegate?.Invoke(); }