![]() |
|
[C#] Unity: How to rescale GUI labels with resolution - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Unity: How to rescale GUI labels with resolution (/showthread.php?tid=5282685) |
Unity: How to rescale GUI labels with resolution - MrJamieMcC - May 26, 2016 Okay so here is my code Code void OnGUI()In the Unity editor and when playing the text is in the correct place. I have the inspector set to 16:9. But when i compile it and select any resolution the text is in the wrong place and at a different size. Does anybody know how to fix this? I googled it a bit and seen something to do with scaling with the screen res. But i dont know how to do that. Thanks * - Yuikoro - May 26, 2016 Program it dynamically. Use Screen to get the width and height of your game's current resolution to work out how big and what not your things should be. I also wouldn't recommend programming your GUIs programmatically because, generally, it isn't as modifiable as when you use the built-in GUI builder on Unity. It also can work with scaling and anchors to ensure your components are in the right spot. Just go to your hierarchy and look for the GUI option, and it'll automatically create the Canvas gameobject and such. * - MrJamieMcC - May 26, 2016 (May 26, 2016 09:19 AM)Sender Wrote: Program it dynamically. Use Screen to get the width and height of your game's current resolution to work out how big and what not your things should be. I also wouldn't recommend programming your GUIs programmatically because, generally, it isn't as modifiable as when you use the built-in GUI builder on Unity. It also can work with scaling and anchors to ensure your components are in the right spot. I regret using GUI labels now but my game is almost finished and i dont want to remake my entire GUI. Hince why i asked how to fix it rather than re-do it * - Yuikoro - May 26, 2016 (May 26, 2016 09:26 AM)MrJamieMcC Wrote: I regret using GUI labels now but my game is almost finished and i dont want to remake my entire GUI. Hince why i asked how to fix it rather than re-do it When taking into account the UI and player enjoyment it might be worth it. But I won't bother you on that any more So as I said earlier, just use the Screen class to get the height and width and work out how each component should be placed, along with their size. The hardest would be figuring out the text font. - I suggest programming the resolutions to be dynamic for certain limits. Such as everything from 400x800 and under will have this GUI size and this font size, everything 400-800 x 800-1200 will have this GUI size and this font size, etc. Whatever sounds easier for you to implement. * - MrJamieMcC - May 26, 2016 (May 26, 2016 09:31 AM)Sender Wrote: When taking into account the UI and player enjoyment it might be worth it. But I won't bother you on that any more Aaaa yea i understand you now. Thank you very much :) |