?? setting orthographic view .problem...

Hello guys,

I have a script attached to the a camera. I have 2 buttons in the OnGUI(): one for the orthographic view and the other for the perspective.
So when I press the first one for the orthographic view I call:

camera.orthographic = true;

when I call the other for the perspective I simply call:

camera.orthographic = false;
The Update() function is empty. I dunno why I click for the orthographic view, I can see it for 1 milli second and then the camera is set back to the perspective view. Why?!
The only way I got to fix that is putting in the Update() this call:

camera.orthographic = orthoBooloean;

where orthoBoolean is set true/false depending on which buttons I clicked on. But, I see this behaviour really weird. WHY!?.

Many thanks
GC.

can you post your OnGUI code

yes :slight_smile:

function OnGUI() {

var swidth : int = Screen.width;
var height : int = Screen.height;

var Sx : int = 10;
var Sy : int = 25;

GUI.skin = skin;

if(GUI.Button(Rect (Sx+ 2*50,Sy,50,50),“”,“B_WALK3D”) ){ //Function which enables Perspective walk

}

if (GUI.Button(Rect (Sx + 3*50,Sy,50,50),“”,“B_HOME”) ){ //Function which reset camera position

transform.position = Vector3(0,50,0);

}
/**********************************/

if (GUI.Button(Rect (Sx + 4*50,Sy,50,50),“”, “B_2D”) ){ //put in TOP 2D VIEW
Set2DView();
}

if (GUI.Button(Rect (Sx + 5*50,Sy,50,50),“”, “B_3D”) ){ //Put in perspective view
Set3DView();
}

if (GUI.Button(Rect (Sx + 6*50,Sy,50,50),“”, “B_ISO”) ){ //Set Isometric View
SetIsometricView();

}

}

This is my Set2DView():
unction Set2DView() {

if (camera.orthographic == false)
previousTransform = camera.transform;

room = GameObject.Find(“Room”); //There is only 1 Room
var roomBounds : Bounds = room.GetComponent(MeshFilter).mesh.bounds;

ortho = true;

camera.orthographic = true;
camera.transform.position = Vector3(0,300,0) + roomBounds.center;
camera.transform.LookAt(roomBounds.center);
camera.orthographicSize =Mathf.Max( Mathf.Max(Mathf.Abs(roomBounds.extents.x), Mathf.Abs(roomBounds.y)), Mathf.Abs(roomBounds.z));

Debug.Log("Bounds:: " + roomBounds);
//Debug.Log("Bounds:: " + roomBounds.size.sqrMagnitude);

}

It all looks right enough.

the only thing might be that Set3DView might be being called somewhere else.

stick a debug.Log in it and see if it comes up everyframe.

hey Geek, thank for your help, but I placed Debug.log s everywhere and the Set3DView is never called.

I’m happy with the solution now, but still I guess it’s really weird that the camera is set back to perspective automatically.