- Home /
Unable to find style 'HUD Button' in skin
I'm following javascript from a book on GUI. I have the correct code for the GUI Skin. Yet I'm getting like "Unable to find style 'HUD Button' in skin 'GameSkin' mouseUp. What is it I need to change in my code or the asset inspector?
var customSkin : GUISkin;
//Display------------------------------------------
function OnGUI()
{
if(customSkin)
GUI.skin = customSkin;
//Moalia's vitals
customControls.LeftStatusMeter(MoaliaImage, playerInfo.health, playerInfo.stamina, lbarImage, lhbar, lsbar);
//Non-usable inventory buttons--------------------------
customControls.InvoHudButton(Rect(Screen.width - 210, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.STAMINA_INJECTOR), staminaInjectorImage, "Avalable Stamina Injectors in inventory.");
}
Answer by Cherno · Aug 21, 2014 at 07:10 PM
In your project folder, find the GUISkin customSkin file, and open it with the inspector. check the custom styles. If there isn't a custom style with the name of "HUD Button", create one.
And you are sure that this GUIskin get used for your OnGUI()? In the inspector, check if the customSkin variable shows the skin that has the HUD Button custom style.
How? I'm getting confused.
And from what the error says: "Unable to find style 'HUD Button' in skin 'GameSkin' Layout UnityEngine.GUIStyle:op_Implicit(String) GUI_CustomControls:InvoHudButton(Rect, Int32, Texture, String) (at Assets/Scripts/GUI/GUI_CustomControls.js:7) GUI_HUD:OnGUI() (at Assets/Scripts/GUI/GUI_HUD.js:41)"
Does this line have to do with the error:
customControls.InvoHudButton(Rect(Screen.width - 210, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.STA$$anonymous$$INA_INJECTOR), sta$$anonymous$$aInjectorImage, "Avalable Sta$$anonymous$$a Injectors in inventory.");
I don't think so.. Let's do it all again.
Create a new GUISkin.
Inside that GUISkin, create a custom GUI Style with the name "HUD Button".
In the script, declare a variable
public GUISkin skin;
Drag the GUI Skin you created from your project folder to the field of the skin variable of the script.
in the script, at the start of the OnGUI() function, insert the line
GUI.skin = skin;
That should be all.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Possible Bug in Unity 4.0.0f7 ? GUISkinn selection Need Help! 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
GUISkin Problem 1 Answer
Assign myGUISkin in javascript 3 Answers