'camera' is not a member of Object

Hi guys,
Im trying to create a game that used the same camera approach as Resident Evil. I want fixed camera angles based on the players position.

I created a script that is attached to the player. There is a trigger tagged ‘trigger1’, and when the player colides with this I want to swap between cam1 and cam2.

I’ve added the cameras to an Array. However I keep getting an error that says ‘camera is not a member of Object’. When enabling a camera I am doing so like this:

cam1.camera.enabled = true

So I dont really know whats wrong with that.

Here is the entire script, with comments. Any feedback would be greatly appreciated. I also dont know if my ‘for loops’ are being used correctly.

#pragma strict
//Camera array
var CameraArray = [];

//3 cameras that can be dragged onto the inspector
var cam1 : Camera;
var cam2 : Camera;
var cam3 : Camera;
//bool that changes each time the player walks into the collider that is used to change camera
private var walkedIntoCollider : boolean = false;

//On start up, the camera array is populated with the 3 cameras
function Start () {
	var CameraArray = [cam1, cam2, cam3];
}

//In one of my corridors there is a collider tagged 'trigger1'. Walking into this is meant to change the 'walkedIntoCollider' bool
function OnTriggerEnter(Col : Collider)
{
	if(Col.tag == 'trigger1')
	{
		walkedIntoCollider = !walkedIntoCollider;
	}
}

function Update()
{
	if(walkedIntoCollider == true)
	{
	//disable all cameras
		for(var cam in CameraArray)
		{
			cam.camera.enabled =false;
		}
		//reinable just camera2
		cam2.camera.enabled = true;
	}
	
	if(walkedIntoCollider == false)
	//Disable all cameras
	{
		for(var cam in CameraArray)
		{
			cam.camera.enabled = false;
		}
		//Reinable just cam1
		cam1.camera.enabled = true;
	}
}

You can fix your immediate problem by changing line 3 to:

  var CameraArray : Camera[];

The issue is that because you did not give ‘CameraArray’ a type, you had an array of objects, so you could not treat the entries as Cameras.

Note you don’t need the cam1, cam2, and cam3. Since CameraArray is public, you can click the triangle next to it to open it, set the size to 3, and then drag and drop the cameras into the array.