2
\$\begingroup\$

How do you calculate the distance from the camera so that a GameObject fills the screen? I.e. Without reaching out of the view and regardless of screen orientation.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can return the difference of transform.position of Main Camera and transform.position of GameObject, if you only want the distance between them.

If you want something else, I think this video might help you

https://www.youtube.com/watch?v=MFQhpwc6cKE

\$\endgroup\$
2
  • 2
    \$\begingroup\$ I think OP is asking not for the current distance between the object & camera, but the required distance they'll need to move the camera to in order for the whole object to fit on screen. \$\endgroup\$
    – DMGregory
    May 11, 2019 at 21:34
  • \$\begingroup\$ Sarvagna Shukla, thanks for your contribution. @DMGregory you're right, it's about finding the required distance to make a GameObject fit onto on the screen. I've edited the question to make it more clear. Thanks for your feedback. \$\endgroup\$ May 11, 2019 at 22:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .