Hider Visibility Events
To run gameplay logic when a revealer sees or loses sight of a hider, subscribe to the revealer's OnHiderVisibilityChanged event.
OnHiderVisibilityChanged
public event Action<FogOfWarHider, bool> OnHiderVisibilityChanged
On a FogOfWarRevealer. The first parameter is the hider in question; the second is its new visibility (true = now seen, false = lost). The event fires from the perspective of that specific revealer.
Example
using FOW;
using UnityEngine;
[RequireComponent(typeof(FogOfWarRevealer))]
public class SightReporter : MonoBehaviour
{
FogOfWarRevealer revealer;
void OnEnable()
{
revealer = GetComponent<FogOfWarRevealer>();
revealer.OnHiderVisibilityChanged += HandleVisibility;
}
void OnDisable()
{
revealer.OnHiderVisibilityChanged -= HandleVisibility;
}
void HandleVisibility(FogOfWarHider hider, bool isVisible)
{
if (isVisible)
Debug.Log($"{name} spotted {hider.name}");
else
Debug.Log($"{name} lost sight of {hider.name}");
}
}
Sample Script
A ready-made example, DrawLineToHiderOnReveal.cs, ships with the package and demonstrates this event by drawing a line from a revealer to each hider it sees. See it in Demo 01 (Pixel-Perfect) — enable the SampleCharacter/Eye/Draw Line To Hider GameObject.
Hider-Side Events
To react to a hider's overall visibility (across all revealers) instead, use the hider's OnActiveChanged event, or attach a Hider Behavior.