Search code examples
unity-game-enginecameraorthographic

Unity 3D Main Camera Orthographic doesn't work after build


I'm newbie with Unity3D.

here is my source, very simple

public void persp_ortho_Btn_Clicked()
{
    if (!Camera_Controller.shared_instance.isOrthoCamera)
    {
        Camera_Controller.shared_instance.isOrthoCamera = true;
        Camera.main.orthographic = true;
        ui_camera.orthographic = true;
    }
    else
    {
        Camera_Controller.shared_instance.isOrthoCamera = false;
        Camera.main.orthographic = false;
        ui_camera.orthographic = false;
    }
}



When i run with this code in Editor (Game simulate window) this works well like below :


1




But, after build and run .exe, main camera doesn't change to ortho camera, also like below :


2




it seems the "orthographic" property of main camera is change true to false, false to true in built runtime as well either. But maybe the view matrix is not changed.

Why this happen and how can i fix this ??


Solution

  • Your code should work unless something is forcing the camera to stay in the same perspective. I am not able to say what might be the cause with the details provided.

    Just test out if the camera will switch without the if statement. Like this

    public void persp_ortho_Btn_Clicked()
        {
            Camera.main.orthographic = !Camera.main.orthographic;
        }
    

    If so, then there is some issue with the condition check.

    Alternatively, you can try using Unity cinemachine to get a smooth transition.