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.

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.

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

public class MultiLimitHotspotCamera : MonoBehaviour
{

    [SerializeField] private Hotspot hotspot;
    [SerializeField] private List<_Camera> limitToCameras = new List<_Camera>();

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

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

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