How To Set Camera To Orthographic Using Script

I’ve set up the camera in my game so it can be toggled between perspective and orthographic modes using a button on my GUI. The camera starts in perspective mode and can be toggled to orthographic. I use camera.orthographic = true. This is where it stops working. I CANNOT set the camera back to perspective.

How can I set the camera back to perspective mode? Why isn’t this working? I’ve looked and looked for an answer to this, and tried a bunch of other camera functions at random and no luck.

        Camera.main.orthographic = false;

This should work… is there another script somewhere else that keeps setting it to orthographic?

I don’t know about switchin camera mode, but may have an intuitive solution for you.

Just use 2 cameras.
One perspective and one orthographic.
Have them transform in tandem (same or cloned transform).

Then you just switch beween them as needed:

var cam1 : Camera;
var cam2 : Camera;
function Start()
{
    cam1.enabled = true;
    cam2.enabled = false;
}

function Update()
{

    if (Input.GetKeyDown(KeyCode.C))
    {
        cam1.enabled = !cam1.enabled;
        cam2.enabled = !cam2.enabled;
    }
}

as seen here:

Nevermind, I’m an idiot, shortly after that I had an if statement

if (camera.orthographic = true) {
do();
}