I have a panel that is anchored to top left. I want to place this panel at the mouse cursor when EventTriggerType.PointerEnter (Im trying to create a hover over tooltip)
I cant get the panel to position correctly by the cursor.
Here is my code that should convert the PointerEventData.position to local space in canvas
private void Show(BaseEventData e)
{
var pe = (PointerEventData)e;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.GetComponent<RectTransform>(), pe.position, pe.pressEventCamera, out var localCursor))
Tooltip.GetToolTip(canvas).Show(this, localCursor);
}
And
public void Show(ToolTipTarget tooltip, Vector2 pos)
{
text.text = tooltip.Text;
gameObject.SetActive(true);
rect.anchoredPosition = pos;
}
The tooltip is parented directly under the canvas
Result