How to set quad to camera size?

Updated on February 27, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on February 26, 2017

Hey guys I am having a problem I am trying to size my quad which is the game background to fill up the camera, sure I can just drag it but want to do it through code. I can get the height but can’t the width.

public Camera cam;
void Start () {
float height = cam.orthographicSize;
gameObject.transform.localScale = new Vector2(cam.orthographicSize * 2, cam.orthographicSize * 2 );

  • Liked by
1 on February 27, 2017

Maybe try this…

public Camera cam;
void Start () {
  float height = cam.orthographicSize * 2;
  float width = height * Screen.width / Screen.height;
  gameObject.transform.localScale = new Vector2(width, height);

Assuming you had the height right, this should adjust your width to fit whichever aspect ratio the camera screen is set to (I think – not tested yet).

on February 27, 2017

Interesting enough recently I found pretty much the same code lol. Thanks.

Show more replies
  • Liked by