# GUIStyle scripting

**URL:** https://discussions.unity.com/t/guistyle-scripting/398760
**Category:** UI
**Tags:** IMGUI
**Created:** [September 27, 2009, 8:25pm UTC](https://discussions.unity.com/t/guistyle-scripting/398760 "2009-09-27T20:25:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_90689794](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anon\_90689794](https://discussions.unity.com/u/anon_90689794)
#### Post date: [September 27, 2009, 8:25pm UTC](https://discussions.unity.com/t/guistyle-scripting/398760/1 "2009-09-27T20:25:22Z")

</div>

Hello,

I recently got really annoyed by my pc errors which mess up my Unity3d scenes.  
It’s nothing serious, because all the scripts are ok, but the problem is that I have tons of GUIStyles and if re-add the script, then I’m gonna have to go through all this process off setting up the GUIStyle via inspector (adding textures, setting widths/ heights etc etc.) which is a real pain…

I decided that the best option to avoid this would be to define all those settings inside scripts so they would be default and I wouldn’t need to do anything in inspector after re-adding script, but how do i do that?

I tried doing something like this:

> [@](#):
>
> var skinas : GUIStyle;
> 
> skinas.fixedWidth = 100;

to define default fixedWidth for that gui style, but it didn’t work. No errors but just didn’t work.

How do you do it? How do you change stuff of guistyle inside script?

thank’s.

---

<div class="post-metadata">

### Author: ![anon\_90689794](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anon\_90689794](https://discussions.unity.com/u/anon_90689794)
#### Post date: [September 28, 2009, 7:54am UTC](https://discussions.unity.com/t/guistyle-scripting/398760/2 "2009-09-28T07:54:51Z")

</div>

wow… anyone?

---

<div class="post-metadata">

### Author: ![anon\_53673431](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@anon\_53673431](https://discussions.unity.com/u/anon_53673431)
#### Post date: [September 28, 2009, 8:56am UTC](https://discussions.unity.com/t/guistyle-scripting/398760/3 "2009-09-28T08:56:14Z")

</div>

I use c# and I put all the Variables Initialization inside this 2 functions .  
void Start()  
{  
}  
void Awake()  
{  
}

---

<div class="post-metadata">

### Author: ![anon\_85768832](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@anon\_85768832](https://discussions.unity.com/u/anon_85768832)
#### Post date: [September 28, 2009, 5:34pm UTC](https://discussions.unity.com/t/guistyle-scripting/398760/4 "2009-09-28T17:34:04Z")

</div>

> [@""](#):
>
> wow… anyone?

Relax, you posted on a Sunday, it’s common for folks to take a day or two off over the weekend. 🙂

As to your problem, you declared a variable that’s of type GUIStyle, but you didn’t actually initialize it.

```auto
var skinas : GUIStyle = new GUIStyle();
skinas.fixedWidth = 100;

```

If you did the above (please post all code when asking for help if you did) are you sure that you’ve applied your GUIStyle to your UI elements properly? Can you share a complete example script where you create and apply a style to a GUI element?
