Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Default camera keeps changing

Discussion in 'Scripting' started by epochplus5, Feb 20, 2022.

  1. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    Hi Guys,

    Not really a scripting question though im sure it could be. I have 2 cameras and to begin with the correct camera was selected when the game starts. Now its starting on my second cam for some reason and my player isnt in that room. It happened before and i was able to fix it by removing it and adding it again and then setting it up in the editor which is a pain.

    Is there an easy way to just set a starting/default camera?
     
  2. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    You go to your second cam and change its tag above the inspector from MainCam to something else
     
  3. epochplus5

    epochplus5

    Joined:
    Apr 19, 2020
    Posts:
    677
    Hey AnimalMan,

    Sorry should have mentioned the tag is set to something else.
     
  4. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    257
    you could use the .depht property of the cameras to switch betweem them.
    Unity uses the camera with the highest one AND uses the main camera if all cameras have the same depht.

    For example, set this property to Zero for both your cameras. and use a similar code.

    Code (CSharp):
    1.     public bool useSecondCam = false;
    2.  
    3.     private void LateUpdate()
    4.     {
    5.         if (useSecondCam)
    6.         {
    7.             Camera.main.depth = -1;
    8.         }
    9.         else
    10.         {
    11.             Camera.main.depth = 0;
    12.         }
    13.     }
    14.  
     
    Last edited: Feb 20, 2022