Setting GUI Skin's Custom Style Size via Javascript (or any code)

alt text

is there a way for me to change the size of Custom Style via scripting?


it's not that I want to create a new skin but to expand/add some more textures and names in the custom styles and I want this done by changing the size of the custom styles as indicated by the image link

for instance, like with how I use the codes below to rename custome styles and add/change textures

public var skin : GUISkin ; 
skin.customStyles[x].name = fileNaming;
skin.customStyles[x].normal.background = screenTexture

I was wondering if there would be something like

skin.customStyles[0].size = 20 ; =; =; =;

    var style1 : GUIStyle;

    function OnGUI()
       { = font1; // assign the font u want here
   style1 =;
   style1.alignment = TextAnchor.MiddleCentre;



If you want to create a new skin, the solution is as simple as this, code shown below (note that EsGUIskin is the name of the skin asset, you must create it before hand):

var myGUISkin : GUISkin;

function Start () {
myGUISkin = Resources.Load("EsGUIskin");

function OnGUI () { = myGUISkin;



The "size" you're talking about is the "length" of customStyles, which is an array of GUIStyles.

Are you trying to declare how many custom styles there will be in your skin?

If so, you probably want to do this:

skin.customStyles = new GUIStyle [20];

I haven't tried it...

When I want to manipulate my custom styles with code, I usually just increase the size of the custom styles array in the inspector first. Then I access the newest GUIStyles in my code like you do in your question.

If for some reason you can’t manually increase the size first, you’d probably have to use a dynamic array to get the job done. You could convert customStyles to a dynamic array, add some styles to the array using Push(), then convert back to a builtin array.

Something like this:

var myCustomSkin  :  GUISkin;

var someStyle     :  GUIStyle;
var anotherStyle  :  GUIStyle;

function Start ()
	var styleArray  =  new Array(myCustomSkin.customStyles);


	myCustomSkin.customStyles  =  styleArray.ToBuiltin(GUIStyle);