UICrosshair - jimdroberts/FishMMO GitHub Wiki

Description

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.


API Access

Fields

  • public Image Image

    The image component used to display the crosshair.

Methods

  • 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.


Basic Usage

Setup

  1. Attach UICrosshair to a UI GameObject in the Unity Editor.
  2. Assign the Image field in the Inspector to the crosshair image component.
  3. Ensure the input manager triggers the OnToggleMouseMode event as expected.

Example

// 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.

Best Practices

  • 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() and Show() methods to control crosshair visibility as needed.
⚠️ **GitHub.com Fallback** ⚠️