- Home /
scaling (Resizing) orthographic camera in 2D mode
Ok guys first time out with 2d games in unity. I hope this is a really simple questiom (But not a dumb one). Can i scale a 2D orthographic camrea like you would a normal object? the height to width ratio is not what i want but i can only seem to scale it in all axis at once, and not change the ratio itself. Im following a tutorial and the camera on there is a different size and ratio to the one that unity created for me. A new camera gives me the same dimensions also. really frustrating as i need the camera ratio to be right as the colliders in the game adjust with it.
Any takers?
Answer by GameVortex · Jan 16, 2014 at 03:09 PM
The size value for orthographic camera basically decides the Height of the camera while the Aspect Ratio of your game decides the width of the camera. When increasing the "height" size on the camera the width is also increased to keep with the current aspect. In the top left of the Game view you can change the current Aspect Ratio to whatever you need it to be.
Remember to later specify in the Player Settings a resolution with the same aspect before you build the game.
Answer by Elon · Jul 15, 2014 at 07:50 PM
I've been though this, heres my code (ofc you can change the min\max numbers) using UnityEngine; using System.Collections;
public class CameraAdjust : MonoBehaviour {
// Use this for initialization
void Start () {
camera.orthographicSize = 6; // Size u want to start with
}
// Update is called once per frame
void Update ()
{
if(Input.GetKey(KeyCode.Q)) // Change From Q to anyother key you want
{
camera.orthographicSize = camera.orthographicSize + 1*Time.deltaTime;
if(camera.orthographicSize > 8)
{
camera.orthographicSize = 8; // Max size
}
}
if(Input.GetKey(KeyCode.E)) // Also you can change E to anything
{
camera.orthographicSize = camera.orthographicSize - 1*Time.deltaTime;
if(camera.orthographicSize < 6)
{
camera.orthographicSize = 6; // Min size
}
}
}
}
Hope you'll find it usefull
Hi, I am trying to use your code, but I am getting following error
error CS1061: Type UnityEngine.Component' does not contain a definition for
orthographicSize' and no extension method orthographicSize' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
Try using UnityEngine.Camera.main. ins$$anonymous$$d of Camera.
Answer by hemankag · Jun 26, 2018 at 03:02 AM
@p_unity. U can change it by clicking on free aspect menu in the top left .u can use the presets, or customize it by clicking on little plus sign in the bottom.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130611im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Orthographic camera movement clamping 1 Answer
How to make a smash bros-like camera 3 Answers
2D Camera size based on unit width 1 Answer
Making a camera semi-orthographic 2 Answers