Enable Child Component C#

Hello.

How would i go about enabling a child camera component?

My player looks like this in hierarchy

Player
   PlayerCamera
      WeaponCamera

I need to enable the Camera component on both camera’s

void OnJoinedRoom()
	{
		GameObject player = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);

		//Camera

		PlayerCamera camera = player.GetComponentInChildren<Camera>();
		camera.enabled = true;

		//Player
		CharacterController characterController = player.GetComponent<CharacterController>();
		characterController.enabled = true;

It is right to use GetComponentInChildren isn’t it? Thanks.

GetComponentInChildren will only get you the first camera component it finds, what you want is GetComponentsInChildren, which will return every camera component in the object’s hierarchy. You can then loop over them to enable the one(s) you want. Make sure you set the includeInactive argument to true, otherwise it will defeat the purpose of the whole thing!

Camera[] cameras = (Camera[]) GetComponentsInChildren(true);
for (int i = 0; i < cameras.Length; i++)
{
	cameras*.enabled = true;*

}