swicth camera to the start

Hi
Should I change the camera to the start
I have seen many topics , but the solutions do not solve my problem .
I am using these two lines of code

cam5.camera.enabled = true ;
cam1.camera.enabled = false ;

( in cam1 there is MainCamera )
I tried plugging in
Start
Awake
OnEnable
but not working
I tried to declare them as well :ù

Public Camera cam1 ;
Public Camera cam5 ;

but not working
Then I tried so

public GameObject cam1 ;
public GameObject cam5 ;

but not working
I also tried with :

Camera.main.enabled = false

but not working

Can you give me some advice ?
Thanks !

ps: sorry for my bad english, I’m Italian

public Camera cam1;
public Camera cam5;

So… with this, you have to do this:
if…
cam1.enabled=true;
cam5.enabled=false;
else…

cam1.enabled=false;
cam5.enabled=true;

Try this

2 Likes

Try this:

cam1.SetActive(false);
cam5.SetActive(true);
1 Like

This should work.

thanks for the responses .
Visiting the help page of Unity “I discovered” the depth parameter that I solved the problem . Thanks for the tips , I learned other useful ways that could help me in the future

Hi all
I have a problem again with cameras
Use the same code for two different cameras at the start, but one works and the other does not
(I also tried the suggestion of Zackhanzo but does not work)

private GameObject LYLA;
  private int position_after_load;
  public Camera cam1;
  public Camera cam6;
   public Camera cam9;
  public bool walk;


void Awake(){
LYLA = (GameObject)GameObject.Find("Lyla_completa_2");//player
}


void Start()
  {
     position_after_load = PlayerPrefs.GetInt("POSITION_AFTER_LOAD");
  
     if (position_after_load == 2)
     {       //work
       cam9.camera.depth = 0;
       cam6.camera.depth = 1;
     }

     if (position_after_load == 3)
     {
        //don't work
       cam6.camera.depth=0;
       cam9.camera.depth=1;
     }


  walk = false;

     switch (position_after_load)
     {
     case 1: break;

     case 2:
       //work
       walk = true;
       cam6.camera.enabled = true;
       cam1.camera.enabled = false;
       LYLA.transform.position = new Vector3(PlayerPrefs.GetFloat("hangar_pos2_x"), PlayerPrefs.GetFloat("hangar_pos2_y"), PlayerPrefs.GetFloat("hangar_pos2_z"));
       LYLA.transform.localEulerAngles = new Vector3(0f, 360f, 0f);
       break;

     case 3:
       //don't work
       walk = true;
       cam9.camera.enabled=true;
       cam1.camera.enabled=false;
       if(GameObject.Find("Camera9")){
         Debug.Log("cam9 found");
         LYLA.transform.position = new Vector3(PlayerPrefs.GetFloat("hangar_pos3_x"), PlayerPrefs.GetFloat("hangar_pos3_y"), PlayerPrefs.GetFloat("hangar_pos3_z"));
         LYLA.transform.localEulerAngles = new Vector3(0f, 90f, 0f);
       }
       break;
     }
  }

I have this result with case 3

EDIT:

But Unity might have a bug to the cameras ?
I rewrote the code , and once again the CAM9 not activated , but activates a completely different camera . Activates a camera that I use to go in first person on occasion

public Camera cam1;
public Camera cam6;
public Camera cam9;

using UnityEngine;
using System.Collections;

public class LOAD_HANGAR_2 : MonoBehaviour {

   public Camera cam1;
   public Camera cam6;
   public Camera cam9;
   public GameObject LYLA;
   public int position_after_load;


   // Use this for initialization
   void Start () {
     position_after_load = PlayerPrefs.GetInt("POSITION_AFTER_LOAD");
     switch (position_after_load) {

     case 1: break;

     case 2:
         //work
       cam6.camera.depth=0;
       cam6.camera.enabled=true;
       cam1.camera.enabled=false;
       LYLA.transform.position = new Vector3(PlayerPrefs.GetFloat("hangar_pos2_x"), PlayerPrefs.GetFloat("hangar_pos2_y"), PlayerPrefs.GetFloat("hangar_pos2_z"));
       LYLA.transform.localEulerAngles = new Vector3(0f, 360f, 0f);
       break;

     case 3:
        //don't work
       cam9.camera.depth=0;
       cam9.camera.enabled=true;
       cam1.camera.enabled=false;
       LYLA.transform.position = new Vector3(PlayerPrefs.GetFloat("hangar_pos3_x"), PlayerPrefs.GetFloat("hangar_pos3_y"), PlayerPrefs.GetFloat("hangar_pos3_z"));
       LYLA.transform.localEulerAngles = new Vector3(0f, 90f, 0f);
       break;
     }
   }

}

EDIT2:

I’m trying so , but the result is not active any camera and I have a blank screen
During the execution , in the inspector the cam9.camera is disabled despite having written
cam9.gameobject.camera.enabled = true

public GameObject cam9;
   public GameObject cam1;
   public GameObject camfp;

case 3:
       cam9.gameObject.camera.depth=0;
       cam9.gameObject.SetActive(true);
       cam9.gameObject.camera.enabled=true;
       camfp.gameObject.SetActive(false);
       cam1.gameObject.SetActive(false);
       cam1.camera.enabled=false;
       LYLA.transform.position = new Vector3(PlayerPrefs.GetFloat("hangar_pos3_x"), PlayerPrefs.GetFloat("hangar_pos3_y"), PlayerPrefs.GetFloat("hangar_pos3_z"));
       LYLA.transform.localEulerAngles = new Vector3(0f, 90f, 0f);
       break;