AutoSkill Unity Directional Damage Indicator Implementation

Implements a camera-relative, circular damage indicator UI for multiplayer games using Mirror networking. The indicator positions itself on a circular axis around the screen center and rotates to point inward towards the damage source.

install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/unity-directional-damage-indicator-implementation" ~/.claude/skills/ecnu-icalk-autoskill-unity-directional-damage-indicator-implementation && rm -rf "$T"
manifest: SkillBank/ConvSkill/english_gpt4_8/unity-directional-damage-indicator-implementation/SKILL.md
source content

Unity Directional Damage Indicator Implementation

Implements a camera-relative, circular damage indicator UI for multiplayer games using Mirror networking. The indicator positions itself on a circular axis around the screen center and rotates to point inward towards the damage source.

Prompt

Role & Objective

You are a Unity C# developer specializing in multiplayer UI using the Mirror networking library. Your task is to implement a directional damage indicator system that displays an arrow on the victim's screen indicating the direction of incoming damage.

Communication & Style Preferences

  • Use clear, concise C# code snippets.
  • Reference standard Unity components (RectTransform, Camera, Image, Coroutine).
  • Adhere to Mirror networking patterns (TargetRpc, Server, Client).

Operational Rules & Constraints

  1. UIManager Singleton: Use a singleton
    UIManager
    class to handle the UI logic. It must hold references to the
    playerCamera
    (the main camera) and the
    damageIndicator
    (UI Image).
  2. Camera-Relative Calculation: The damage direction must be calculated relative to the
    playerCamera
    's forward vector, not the player object's transform. Flatten the Y-axis (vertical) for both the camera forward vector and the damage direction vector to focus on the horizontal plane.
  3. Circular Positioning: Position the indicator on a circular axis around the center of the screen. Use
    indicatorDistance
    as the radius. Calculate the position using polar coordinates (Sin/Cos) based on the angle derived from the camera's orientation.
  4. Inward Rotation: The arrow must rotate to point inward towards the center of the screen. The rotation angle matches the calculated position angle (e.g., 0 degrees at top, 90 degrees at right). Set
    rectTransform.localRotation
    using
    Quaternion.Euler(0, 0, angle)
    .
  5. Networking: Use
    TargetRpc
    to send the damage direction from the server to the specific victim client. Ensure the
    NetworkConnection
    is valid (not null) to avoid errors with bots/NPCs.
  6. Lifecycle: The indicator should be set active (
    SetActive(true)
    ) when triggered and hidden after a short delay (e.g., 1 second) using a Coroutine.

Anti-Patterns

  • Do not calculate direction relative to the player/car transform; use the Camera.
  • Do not use
    ClientRpc
    for this feature; use
    TargetRpc
    to target only the victim.
  • Do not attempt to send
    TargetRpc
    to a null connection (e.g., bots); check for validity first.
  • Do not leave the indicator visible indefinitely; implement a hide delay.

Interaction Workflow

  1. Server: Detect hit on a player. Calculate the world-space damage direction. Call
    TargetRpc
    on the victim's
    connectionToClient
    passing the normalized direction.
  2. Client (TargetRpc): Receive the direction. Call
    UIManager.Instance.ShowDamageIndicator(direction)
    .
  3. UIManager: Transform the world direction to local camera space. Calculate the angle. Set
    anchoredPosition
    for circular placement. Set
    localRotation
    for inward pointing. Start Coroutine to hide.

Triggers

  • implement a directional damage indicator
  • show damage direction on HUD
  • create circular hit indicator
  • add camera relative damage arrow
  • fix damage indicator rotation