Hi
I want to have a hierarchy of game objects set to not-active when a Hotspot is off-camera, effectively when the hotspot State goes to Off. I have the following code but the it doesn't get triggered when the State changes of the specified Hotspot. Am I using the correct delegate? The OnEnable/Disable functions are called, but the onAction and offAction functions don't get called.
public UnityEvent onHotspotOn;
public UnityEvent onHotspotOff;
public Hotspot hotspot;
void OnEnable()
{
EventManager.OnHotspotTurnOn += onAction;
EventManager.OnHotspotTurnOff += offAction;
}
void OnDisable()
{
EventManager.OnHotspotTurnOn -= onAction;
EventManager.OnHotspotTurnOff -= offAction;
}
void onAction(Hotspot tempHotspot)
{
if (hotspot == tempHotspot)
{
onHotspotOn?.Invoke();
}
}
void offAction(Hotspot tempHotspot)
{
if (hotspot == tempHotspot)
{
onHotspotOff?.Invoke();
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
You've confirmed its not onHotspotOn that's not being called, but onAction? As in, a Debug.Log command never fires regardless of the Hotspot parameter value?
The AC event-hooking looks correct.
I've put a breakpoint on
if (hotspot == tempHotspot)
and it never triggers. It does atEventManager.OnHotspotTurnOn += onAction;
so it would feel that the IF line in doAction is never actioned.However, just to test I've put some debug lines in and those debug lines show no results in the console, but the OnEnable and OnDisable both work.
The logs fire when testing on my end - the code is fine.
How/when are you affecting Hotspots? With the Hotspot: Enable or disable Action?