Array for multiple cameras?

Hi, I was looking for a way to put multiple cameras in an array, and when you enter a trigger, it would snap to a certain camera depending on the trigger

Now the way I thought of doing this is when you enter a trigger, you feed the array value the appropriate number, but if there are alot of cameras in a scene, this could become time consuming, assuming you have to create a separate script for each trigger.
Is there an easier way to do this with OnTriggerEnter()? Or are there easier methods to do this
Not asking for code at all, but should you do, please try to explain it, tryin to learn here =D
Please let me know if you need any additional info!
Thanks again for your time.

So you need to declare an array of cameras in your player script. Each camera must be disabled but the one you want to start with.

Then in the method OnTriggerEnter (also in your player script), you need to collect the important information for you (it can be the name of the cube for example).

You could have something like that :

function OnTriggerEnter (other : Collider) {
        switch (other.name)
        {
            case "Trigger1":
                EnableCamera(1);
                break;
            case "Trigger2":
                EnableCamera(2);
                break;
            case "Trigger3":
                EnableCamera(3);
                break;
        }
    }

Then you declare a method EnableCamera that will disable the current enabled camera (you can memorize the index in a variable to avoid disabling all cameras) and enable the good one in your array.

The way i would do this is to have a public gameobject that has a List that contains all your cameras and call it “_cameras”, then assign all your camera to this list in the inspector giving them all appropriate names. then on each trigger have a public Camera and assign the appropriate camera and a public Gameobject which you assign to the cameras gameobject.

Then use this script on your gameobject that contains all the cameras:

enter code here

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

public class Cameras : MonoBehaviour 
{	
	public List _cameras = new List();
	
	public void EnableCam(Camera targetcam)
	{
		foreach(Camera camera in _cameras)
		{
			if(camera != targetcam)
			{
				camera.enabled = false;
			}
			else
			{
				camera.enabled = true;
			}
		}
	}
} 

Then use this script on your triggers that contains all the cameras:

using UnityEngine;
using System.Collections;

public class TriggerScript : MonoBehaviour 
{
	public GameObject cameraHolder;
	public Camera targetCam;
	
	void OnTriggerEnter(Collider other) 
	{
		if(other.tag == "player")
		{
			cameraHolder.GetComponent<Cameras>().EnableCam(targetCam);
		}
	}
	
}