Find and turn off previous camera?
I want to make some changes to my fixed camera script. it is a trigger that chooses to use the camera attached, then upon exiting the camera is deactivated. I have many cameras with these trigger scripts in my scene. What I'd like to do is this: Instead of deactivating the current camera upon exit, at the moment the current camera is set to enabled true I then want to find the previous camera that was in use and deactivate THAT. I hope this makes sense.
Thanks in advance.`
var gameCamera : GameObject;
private var inSide : boolean = false;
function Start()
{
}
function OnTriggerStay(Col : Collider)
{
if(Col.tag == "Player")
{
inSide = true;
}
}
function OnTriggerExit(Col : Collider)
{
if(Col.tag == "Player")
{
inSide = false;
}
}
function Update()
{
if(inSide == true)
{
gameCamera.GetComponent.<Camera>().GetComponent.<Camera>().enabled = true;
}
if(inSide == false)
{
gameCamera.GetComponent.<Camera>().GetComponent.<Camera>().enabled = false;
}
}
Answer by bathorsthroat · Feb 13, 2017 at 09:41 PM
This is the best that I could come up with is anyone is having the same trouble. It's probably not the best approach but it's all I could figure out. Just place this script onto the same trigger object that activates the camera.
#pragma strict
public var currentCam : Camera;
function Start () {
// Enable the first camera
currentCam = Camera.allCameras[0];
// disable all other cameras
for ( var i:int = 1; i < Camera.allCameras.Length; i ++ )
{
Camera.allCameras[i].enabled = false;
}
}