L
L
LittleBob2021-10-24 17:52:49
Unity
LittleBob, 2021-10-24 17:52:49

How to find out the length of the Canvas in units through a script in Unity?

As far as I know, these squares in the Scene window are called units. To optimize the game for different devices, I need to get the actual value of the Canvas length in units through the script, is this possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2021-10-24
@LittleBob

Well, somewhere at the level of theory - translate screen coordinates into world coordinates. The camera has methods (ScreenPointToWorld). But this will work adequately only for an orthographic camera - as soon as you add depth, you will have to contrive more.

P
ProstoLubitel, 2021-10-24
@ProstoLubitel

There is a simpler option, which is about canvas for different resolutions. You just need to add a few components that already exist in unity (I don’t remember now, but I can look if you are interested) that themselves adapt the canvas and its contents to different resolutions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question