GUI.Button - Texture, Text, dropdown - Go from 1,900 FPS to 19FPS when i click the "Buildings" button

Strange behavior When using the GUI buttons. (My fault not unity of course :) )

I have here, a Gui Script, That when "Buildings" is clicked, it drops down a list of "Buildings" that can be purchased.

Each one is linked to a 2D Texture. Now, the problem i am having is.

Clicking the button for Buildings - My game slows down to about 19 - 20 FPS. with nothing really rendering, but a capsule, a couple of boxes, and a small flat terrain.

Here is the Script:

var showMoreGui = false; 
var icon1 : Texture2D;
var icon2 : Texture2D;
var icon3 : Texture2D;
var icon4 : Texture2D;
var icon5 : Texture2D;

function OnGUI () { 
    if (GUI.Button (Rect (10,10,100,20), "Buildings")) 
        showMoreGui = true; 

    if (showMoreGui) 
        ExtraGUI (); 
} 

function ExtraGUI () { 
    GUI.Button (Rect (10, 40,100,20), icon1, "Shack"); 

    GUI.Button (Rect (10, 60,100,20), icon2, "Cottage"); 

    GUI.Button (Rect (10, 80,100,20), icon3, "Cobblestone House"); 

    GUI.Button (Rect (10, 100,100,20), icon4, "Townhouse"); 

    GUI.Button (Rect (10, 120,100,20), icon5, "Windmill"); 

    if (GUI.Button (Rect (10, 140,100,20), "Close")) 
        showMoreGui = false; 
} 

Now, during Runtime - I get the following Message:

Unable to find style 'Windmill' in skin 'GameSkin' repaint UnityEngine.Debug:LogWarning(Object) UnityEngine.GUISkin:GetStyle(String) UnityEngine.GUIStyle:op_Implicit(String) NewBehaviourScript:ExtraGUI() (at Assets\Scripts\NewBehaviourScript.js:27) NewBehaviourScript:OnGUI() (at Assets\Scripts\NewBehaviourScript.js:15) UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean) UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean) UnityEditor.GameView:OnGUI() System.Reflection.MonoMethod:InternalInvoke(Object, Object[]) System.Reflection.MonoMethod:InternalInvoke(Object, Object[]) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) System.Reflection.MethodBase:Invoke(Object, Object[]) UnityEditor.HostView:Invoke(String) UnityEditor.DockArea:OnGUI()


On a side note, i was looking through the Script Refernce Manual: Found the Style part, try to implement it, and I get syntax errors.. ACCKKK!!!!

Any help would be appreciated as always :)

You aren't using GUI.Button right. You can't do this:

GUI.Button (Rect (10, 40,100,20), icon1, "Shack"); 

because that means it will use `icon1` as the texture for the button itself, and then it will search inside the current GUI skin for the style named "Shack", and try to apply it. Since it doesn't exist, it's causing lag for your game.

There is no Button definition for "image + text", so you need to make a custom GUIContent object instead, like this:

GUI.Button (Rect (10, 40,100,20), new GUIContent("Shack", icon1));