FANDOM


Hotspots have a Limit to camera field, which causes them to only be active when the chosen camera is active.  However, only one camera can be selected.   This script allows you to define multiple limiting cameras for a given Hotspot, as well as negate the effect - to prevent a Hotspot from being interactive if a given camera is active.

To use it, paste the code in a C# script named MultiLimitHotspotCamera, attach it to a Hotspot, and fill out the fields in the Inspector.

To negate the effect, check "Negate Effect" and assign an unused GameCamera in the "Dummy Cam" field.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using AC;

public class MultiLimitHotspotCamera : MonoBehaviour
{

[SerializeField] private Hotspot hotspot = null;
[SerializeField] private List<_Camera> limitToCameras = new List<_Camera>();
[SerializeField] private bool negateEffect = false;
[SerializeField] private _Camera dummyCam = null;


private void OnEnable ()
{
EventManager.OnSwitchCamera += SwitchCamera;
}


private void OnDisable ()
{
EventManager.OnSwitchCamera -= SwitchCamera;
}


private void SwitchCamera (_Camera old, _Camera newCamera, float transitionTime)
{
if (negateEffect)
{
if (limitToCameras.Contains (newCamera))
{
hotspot.limitToCamera = dummyCam;
}
else
{
hotspot.limitToCamera = newCamera;
}
}
else
{
if (limitToCameras.Contains (newCamera))
{
hotspot.limitToCamera = newCamera;
}
}
}

}
Community content is available under CC-BY-SA unless otherwise noted.