- Home /
A questão foi respondida e dada como aceite
Scaling GameObjects by Screen Resolution
I have a container with many SpritesRenderer. I need scale this container by Screen Resolution. I've tried many things and do not know how do = /
I cant keep the screen size LocalScale or slightly less (I would leave him with an edge on the screen as the picture below).
If I could pick up the container size and calculate its size related to the size of the screen, it would be the ideal for me because I need always resize this container in various situations and different screens.
OBS: I cant use UI, because i need manipulate with drag and drop theses sprites, so i need of Box Collider, what not work on UI, between other things... I managed to make this resize the UI, but as I mentioned, that way does not help me.
I don't see why UI can't work.. but you can access the screen size and other informatins here: https://docs.unity3d.com/ScriptReference/Screen.html
There's absolutely no reason why you can't use the UI for drag and drop, two of my recently released games use nothing but UI elements for the display graphics and they are both touch and drag type games. Also the drag and drop inventory system for the RPG game I'm currently working on is implemented using the Unity UI components.
I'd suggest you look into using the UI for your problem as it will be the easiest way to keep things scaled with the screen size, and if you need help getting it working make a thread in the forum and ask for help.
Understood. I did resizing UI, I'll try to change my drag to the UI. thank you! One more thing, I can tell if Drop upon some element, as BoxCollider?
I did it Drop areas, really thanks you for the statement!
If using the UI then put the anchors to the corners of each element and it should scale with the screen resolution. Different aspect ratios may well look stretched or squashed though.
You could always do a rough calculation of the aspect ratio from screenHeight and screenWidth and then have a few differing Canvases so one for 4:3 one for 16:9 one for 16:10 there are only a few aspect ratio's as opposed to resolutions so it's extra work but not too much.
Follow this Question
Related Questions
Imported Scale Animation Ignored in Viewport 0 Answers
Sprite renderer scaling 0 Answers
How to scale an object clone to fit a cube 2 Answers
Ui elements not scaling correctly 0 Answers
Particle System Scaling - Not working for velocities 2 Answers