Change camera projection

Hello! Im trying to make a button that change the camera projection, eg: perspective to orthographic or orthographic to perspective.
In my script i have this
if(GUI.Button(new Rect (10,35,150,20), “Projection”))
{
//I need to put something here that change the projection, but i cant find in the manual or in scripting api anything.
}

im sorry for my english, i apreciate your help!

Camera.main.orthographic = true;
3 Likes

This isn’t really what you’re asking for help with, but the whole OnGUI-based system is pretty obsolete now, and you’re much better off not using it. Check out the tutorials on the new UI system instead.

And what happend if the Camera isnt the main camera? I put
Camera.current.orthographic = true;
But it doesnt work

Camera.current only works in certain functions (like OnPreRender), and it’s not what you’re looking for here.

You need to get a reference to the camera somehow or other. Most likely, you want this:

public Camera adjustCamera;

Put that in the main body of the class (outside your functions). Now, in the inspector, you will see a ‘slot’ (named “Adjust Camera”) into which you can drag the camera you want to affect. Now, adjustCamera.orthographic will get you what you want.

thanks i’ve been looking for a property called projection !!
:smile: thanks