How do I enable/disable a camera on an instantiated prefab?

What I’m doing is loading my Player Character as a prefab which then has the ability to instantiate a 2nd prefab that is supposed to be able assume control while the player character is locked in place.

The prefab instantiated by the player character and the player character has a camera (nested) attached to them. I’m trying to slect the prefab’s camera so that when the player is controlling the prefab te prefab’s camera is active as the main camera.

The problem I’m running into is that I can’t figure out how to refer to the prefab’s camera to activate or deactivate it.

“gameObject.GetComponent” only refers to the components of the prefab and not to the nested camera so I’m lost.

Here’s the script as I have it now…

public class PlayerController : MonoBehaviour {

	public float rotateSpeed;
	public float forwardSpeed;
	public float jumpHeight;
	public Transform Armana;
	public Camera MainCamera;

	private Camera ArmanaCam;
	private CharacterController playerController;
	private bool PlayerActive = true;

	// Use this for initialization
	void Start () {
		playerController = GetComponent<CharacterController> ();
		MainCamera.enabled = true;
	}

	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown (KeyCode.Q)) {
			if (PlayerActive) {
				PlayerActive = false;
				Armana.GetComponent<PMonsterController>().enabled = true;
				MainCamera.enabled = false;
				MainCamera.GetComponent <AudioListener>().enabled = false;
				ArmanaCam.enabled = true;
				ArmanaCam.GetComponent <AudioListener>().enabled = true;
			} else {
				PlayerActive = true;
				Armana.GetComponent<PMonsterController>().enabled = false;
				ArmanaCam.enabled = false;
				ArmanaCam.GetComponent <AudioListener>().enabled = false;
				MainCamera.enabled = true;
				MainCamera.GetComponent <AudioListener>().enabled = true;
			}
		}

		if (Input.GetKeyDown (KeyCode.E)) {
			Instantiate (Armana, transform.position, transform.rotation);
			//Assaign ArmanaCam... somehow
			ArmanaCam.enabled = false;
			ArmanaCam.GetComponent <AudioListener>().enabled = false;
		}

		if (PlayerActive) {
			if (Input.GetButton ("Jump") && playerController.isGrounded) {
				playerController.Move (Vector3.up * jumpHeight);
			}

			transform.Rotate (0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
			Vector3 forward = transform.TransformDirection (Vector3.forward);
			float speed = forwardSpeed * Input.GetAxis ("Vertical");
			playerController.SimpleMove (speed * forward);
		}
	}
}

@Durakken
I’m not sure if you ever figured out how to solve this issue of yours. I ran into a similar problem with my own project. I was instantiating some vehicles with cameras attached but inactive. I wanted to pick a vehicle out of the various spawned ones to control, but needed to have the desired cameras become active and I found that I could not do this from the spawn script directly. I eventually got it to work by attaching an “EnableCameras” script to the vehicle prefab that looked like this:

public class EnableCameras : MonoBehaviour
{

    [SerializeField] public Camera RightRear;
    [SerializeField] public Camera LeftRear;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.D))
        {
            RightRear.GetComponent<Camera>().enabled = true;
            LeftRear.GetComponent<Camera>().enabled = true;
        }
    }

Then in my spawner script, I enabled the “EnableCameras” script whenever the player decides to take control of their desired vehicle:

whatToSpawnClone[j].GetComponent<UnityStandardAssets.Vehicles.Car.EnableCameras>().enabled = true;

Perhaps not the most elegant solution, but it did work for the purpose of activating the cameras in a particular instantiated prefab.