void LateUpdate() { var mousePosition = _mousePositionManager.GetMousePosition(); var screenSize = _mousePositionManager.GetCanvasSize(); var targetPosition = new Vector2( Mathf.Clamp(mousePosition.x, padding.x, screenSize.x - padding.x), Mathf.Clamp(mousePosition.y, padding.y, screenSize.y - padding.y) ); _rectTransform.anchoredPosition = Vector2.Lerp(_rectTransform.anchoredPosition, targetPosition, smoothSpeed * Time.deltaTime); }
void LateUpdate() { var pos = _mousePositionManager.GetMousePosition(); Vector2 anchoredPosition; var targetPosition = new Vector2( Mathf.Clamp(pos.x, bounds.x, bounds.y), (anchoredPosition = _rectTransform.anchoredPosition).y ); _rectTransform.anchoredPosition = Vector2.Lerp(anchoredPosition, targetPosition, movementSpeed * Time.deltaTime); _rectTransform.rotation = Quaternion.Euler(new Vector3(0, 0, pos.y > anchoredPosition.y ? 0 : 180)); }