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.
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
}
}
}
}
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.
@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.