How to enable a childs camera

If you guys could help that would be great. I have a plane game I am working on and I have a camera that is attached to the plane that looks for the closest target once the plane is in the air. I have code that also uses the scroll wheel to zoom into the target. The problem is the plane is so high that I can’t get a closer zoom of the targets to see what they are. So I put a camera on the targets so that when the max of the scroll wheel is reached the camera of he target will come on. So now I can’t get the camera to be enabled on the targets. I can find the game object that is the closest but I can’t figure out how to turn the camera on because it is a child of the target.

var speed : float ;
var turn : float;
var a=100;
var b=2;
var mcamera:Camera;
var myTarget: GameObject;


 function Update()  {

 if (Input.GetAxis("Mouse ScrollWheel") > 0 && mcamera.fieldOfView > b)

{
 mcamera.fieldOfView--;
 }

if (Input.GetAxis("Mouse ScrollWheel") < 0 && mcamera.fieldOfView < a)
 {
  mcamera.fieldOfView++;
 }
 
FindClosestEnemy();
//print(FindClosestEnemy().name); 
myObject = FindClosestEnemy().name; 

  if(mcamera.fieldOfView == 0){
  
 print ("field of view is at zero");
 //This is where I want the camera of the target to come on.
    
 }
 }
 function FindClosestEnemy () : GameObject {
    // Find all game objects with tag target
    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag("target"); 
    var closest : GameObject; 
    var distance = Mathf.Infinity; 
    var position = transform.position; 
     
    // Iterate through them and find the closest one
  
    for (var go: GameObject  in gos)  { 
        var diff = (go.transform.position - position);
        var curDistance = diff.sqrMagnitude; 
        if (curDistance < distance) { 
            closest = go; 
            distance = curDistance; 
           
            myTarget  = closest;
            //Here I can print to find the target just need to know how to turn on the camera
             print(myTarget);
          
        } 
        
    } 
      
      
     transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(closest.transform.position - transform.position), turn*Time.deltaTime);
   transform.position += transform.forward*speed*Time.deltaTime;
   return closest;
}

Thanks guys for your help this worked!!

myTarget.transform.Find(“Camera”).GetComponent(Camera).enabled = false;

I believe this is what you’re looking for to control your camera:

myTarget.GetComponent<Camera>().enabled = true;

try this

 Transform childCamTransform = myTarget.FindChild("yourChildCameraName");

if( childCamTransform ) childCamTransform.camera.enabled = true;
else print( "No child camera found for myTarget" );

I am using JavaScript so I think it should be like this.
myTarget.GetComponent(Camera).enabled = true;

With this it should just enable the the camera of the closest target to turn on but I get an error.

NullReferenceException: Object reference not set to an instance of an object

 function FindClosestEnemy () : GameObject {
    // Find all game objects with tag Enemy
    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag("target"); 
    var closest : GameObject; 
    var distance = Mathf.Infinity; 
    var position = transform.position; 
     
    // Iterate through them and find the closest one
  
    for (var go: GameObject  in gos)  { 
        var diff = (go.transform.position - position);
        var curDistance = diff.sqrMagnitude; 
        if (curDistance < distance) { 
            closest = go; 
            distance = curDistance; 
           
           myTarget  = closest;
            
           //  print(myTarget);
         myTarget.GetComponent(Camera).enabled = true;
        } 
        
    } 
       //return closest;   
     transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(closest.transform.position - transform.position), turn*Time.deltaTime);
   transform.position += transform.forward*speed*Time.deltaTime;
   //return closest;
}

Guys thanks for you help but I am getting errors with this. I can’t find anything with FindChild.

Transform childCamTransform = myTarget.FindChild("yourChildCameraName");