Skip to content

VisibilitySwitch

The VisibilitySwitch component enables GameObjects to receive events about visibility state changes in the fog of war system. The object is considered visible when at least one of its checkpoint positions is within range of any VisionSource. Checkpoint positions are offsets relative to the GameObject's position and rotation.

Rotation Behavior

The rotation behavior depends on the Orientation setting in the FogOfWarManager:

  • XZ orientation (top-down games): Uses the GameObject's Y-axis rotation
  • XY orientation (2D side-scrolling games): Uses the GameObject's Z-axis rotation

Usage

  1. Add the VisibilitySwitch component to any GameObject that should receive events about fog visibility changes.

  2. Configure the component properties in the Inspector.

Inspector Properties

VisibilitySwitch Inspector

  • Use Center As Checkpoint: When enabled, uses only the GameObject's center position (0, 0) as a single checkpoint. When disabled, allows you to define custom checkpoint positions in the Check Points list.

  • Check Points: (This property appears only if "Use Center As Checkpoint" is unchecked) A list of Vector2 positions relative to the GameObject's position and rotation. The object is considered visible if any checkpoint position is within range of a VisionSource. At least one checkpoint is required.

  • On Become Visible: A UnityEvent triggered when the object transitions from hidden to visible state.

  • On Become Invisible: A UnityEvent triggered when the object transitions from visible to hidden state.

Public API

  • bool IsVisible - Returns true if the object is currently visible, false if hidden (read-only).

  • event Action<bool> OnVisibilityChanged - A C# event triggered when visibility state changes. The boolean parameter is true when becoming visible, false when becoming hidden.