hi,
how to change the size of orthographic camera?
i try this but doesn’t work
var zoom = 100;
var MainCamera : GameObject ;
function ZoomCamera() {
MainCamera.GetComponent("Camera").size = zoom;
}
hi,
how to change the size of orthographic camera?
i try this but doesn’t work
var zoom = 100;
var MainCamera : GameObject ;
function ZoomCamera() {
MainCamera.GetComponent("Camera").size = zoom;
}
If you want to use a reference variable, you should declare it as Camera and reassign the gameobject. That way you directly have a reference to the Camera component:. Also variable names should start with a lower character.
Next thing is that the camera doesn’t have a variable / property that is called “size”, it’s called orthographicSize.
var zoom = 100;
var mainCamera : Camera; // assign in the inspector
function ZoomCamera()
{
mainCamera.orthographicSize = zoom;
}
If there is only one camera tagged “MainCamera” you could simply use Camera.main
var zoom = 100;
function ZoomCamera()
{
Camera.main.orthographicSize= zoom;
}
If you really want to use a GameObject reference in combination with GetComponent (this is the slowest way), do it like this:
var zoom = 100;
var mainCamera : GameObject; // assign in the inspector
function ZoomCamera()
{
mainCamera.GetComponent(Camera).orthographicSize = zoom;
}