- Home /
Properly resizing skin in code
Hey,
I'm not sure how to approach this the right way:
I'm having a GUISkin, which I setup in the Inspector. In order for everything to look the same size on different screens however, I want to resize some of the values during runtime. What I've tried is to set the values like this:
guiSkin.button.fixedWidth = guiSkin.button.fixedWidth * (DefaultScreenSize.x / Screen.width);
and the same thing for every other value I want to resize, everything happening in the Start() method. What I realized trying this, is that guiSkin apparently directly accesses and changes the Values in the Inspector, so after the game my default values are all messed up and so is the resizing when restarting the game. I could save all the standard values and reset them once the game is ended, but I feel that would lead to a lot of bugs, for example if the game is not properly endet.
So: what would be the right way to approach this? I've tried several, but all of them seem to have some drawbacks to them.
thanks,
Topsy
EDIT: Tried adding options to the button like this:
GUILayout.Button("Play", GUILayout.Width(50));
But it doesn't affect the buttons width...
EDIT 2: Ok, here's my solution: In order to not affect the original skin I "clone" it, by creating an instance of it:
GUI.skin = Instantiate(guiSkin);
So now changes I do to GUI.skin don't change guiSkin anymore. Not sure how good a solution this is, but it works :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613155100im_/https://answers.unity.com/themes/thub/images/avi.jpg)