So, I have my UI, and I want my camera viewport to fit in the remaining part of my screen. I did it for one resolution, but when I scale game window, things get broken.
Here is how it looks when it’s ok:
And when I scale window:
I want my camera to fit in this “empty” area with any resolution.
Alright, so here is my solution:
using UnityEngine;
using System.Collections;
public class CamVPFit : MonoBehaviour {
float height, UIPheight;
public GameObject UIPanel;
void Start () {
UIPheight = UIPanel.GetComponent<RectTransform>().rect.height;
height = Screen.height*1.0f;
Camera.main.rect = new Rect (0,UIPheight/height,1,1);
}
}
Works just perfect.