UICrosshair - jimdroberts/FishMMO GitHub Wiki
UICrosshair
is a UI component in the FishMMO client that manages the crosshair image. It shows or hides the crosshair based on the mouse mode, subscribing to mouse mode toggle events from the input manager.
-
public Image Image
The image component used to display the crosshair.
-
public override void OnStarting()
Called when the crosshair UI is starting. Subscribes to mouse mode toggle event.
-
public override void OnDestroying()
Called when the crosshair UI is being destroyed. Unsubscribes from mouse mode toggle event.
-
public void OnToggleMouseMode(bool mouseMode)
Handles mouse mode toggle event. Hides crosshair when mouse mode is enabled, shows when disabled. Parameters: bool mouseMode – True if mouse mode is enabled, false otherwise.
- Attach
UICrosshair
to a UI GameObject in the Unity Editor. - Assign the
Image
field in the Inspector to the crosshair image component. - Ensure the input manager triggers the
OnToggleMouseMode
event as expected.
// Example: Using UICrosshair in a scene
UICrosshair crosshair = GetComponent<UICrosshair>();
crosshair.Image = ...; // Assign Image component
// The crosshair will automatically show/hide based on mouse mode events.
- Always assign the
Image
field in the Inspector to avoid null references. - Ensure the input manager is properly configured to trigger mouse mode events.
- Use
Hide()
andShow()
methods to control crosshair visibility as needed.