Problem switching between multiple cameras

I’m new to Unity and I need some help with a problem I’m having switching between multiple cameras. Here’s the setup that I’m working with.

  1. I’m running Unity3D 4 on OSX Mountain Lion
  2. My game consists of a series of levels with corridors that connect to various rooms. You navigate the corridors and most of the rooms with a first person controller.
  3. In some rooms the task changes so I need to change the viewpoint to a different position that tracks a different object. These rooms have the object that I’m tracking (the Deflector) as a child of the room (the Arena) and the camera (Camera) is a child of the deflector. It’s best to track the deflector in the local space of the room than world space because it simplifies things greatly.
  4. Each arena has a number appended to the name for identification so the first is Arena1 and the next Arena2, etc.
  5. Each Arena has a trigger to detect entry and exit into the room. The trigger script has a variable that identifies the selected room to help you find all the objects within the arena.

Everything works well with a single arena. When you enter the arena the deflector’s camera is moved to the location and orientation of the FP camera. The camera transitions to the play position and the task starts. However, if I make a copy of the arena in a different location, change the appended ID number and the ID in the script only one arena works correctly. Entering the other arena causes all of the objects to work as they should in the proper arena but the camera is stationary in the other arena. The code that makes the switch is attached to the deflector and looks like this:

function SetSelect(newState)
	{
	// Set the new selected state
	selected = newState;
	
	// Get the parent arena object
	pParent = transform.parent.gameObject;
	// Get the deflector object
	pDeflector = gameObject;
	// Get the camera object (child of deflector)
	pCamera = pDeflector.transform.Find("Camera").gameObject;

	// Get the orb object (child of parent, sibling of deflector)
	pOrb = pParent.transform.Find("Orb").gameObject;
	
	if (selected)
		{
		pMainCamera.camera.enabled = false;
		pMainCamera.GetComponent(AudioListener).enabled = false;
		pCamera.camera.CopyFrom(pMainCamera.camera);
		pCamera.camera.enabled = true;
		pCamera.GetComponent(AudioListener).enabled = true;
		}

		inAlignment = true;
	}

I know that I’m pointing to the correct gameObjects because I can view things in the scene view while the game is running and see all the correct objects moving in the correct arena - the wrong camera is just selected. Does anyone have any suggestions?

Mario

Someone throw me a bone… :slight_smile:

I guess I’m on my own…

Never mind. I’ve decided to take a different approach.