UITooltip - jimdroberts/FishMMO GitHub Wiki
UITooltip
is a UI control in the FishMMO client that displays a tooltip with text near the mouse cursor. It updates its position each frame to follow the mouse and adjusts its offset to stay on screen.
-
public TMP_Text Text
The text component used to display the tooltip content.
-
public RectTransform Background
The background RectTransform for positioning and sizing the tooltip.
-
void Update()
Updates the tooltip position each frame to follow the mouse, adjusting vertical offset if near the top or bottom of the screen.
-
public void Open(string text)
Opens the tooltip with the specified text, positions it near the mouse, and shows it. Parameters: string text – Text to display in the tooltip.
- Attach
UITooltip
to a UI GameObject in the Unity Editor. - Assign the
Text
andBackground
fields in the Inspector. - Call
Open()
to display a tooltip with the desired text.
// Example: Showing a tooltip on mouse hover
UITooltip tooltip = GetComponent<UITooltip>();
tooltip.Text = ...; // Assign TMP_Text
tooltip.Background = ...; // Assign RectTransform
// To show a tooltip:
tooltip.Open("This is a tooltip!");
- Always assign the
Text
andBackground
fields in the Inspector to avoid null references. - Use the
Open()
method to display tooltips with dynamic content. - Ensure the tooltip stays within screen bounds by using the provided offset logic.