0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Unity] Scale With Screen Size / Expand のCanvasのUIと同じ大きさに見えるようにObjectをScaleさせる

Posted at
var referenceWidth = 1334;
var referenceHeight = 750;

var cam = Camera.main;

var resolutionAspect = (float)referenceWidth / referenceHeight;
var camAspect = cam.aspect;

var fov = cam.fieldOfView * Mathf.Deg2Rad * 0.5f;
if (resolutionAspect > camAspect)
{
    var hTan = Mathf.Tan(fov) / (1 / camAspect * resolutionAspect);
    fov = Mathf.Atan(hTan);
}
 
var distance = Vector3.Distance(transform.position, cam.transform.position);     
transform.localScale = Mathf.Sin(fov) * distance * Vector3.one;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?