Hi ! when I open my chest in game i had this error with GUI :
Unable to find style 'Close Window Button' in skin 'ChestSkin' Repaint
Here is all code for chest:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MyGUI : MonoBehaviour {
public GUISkin MySkin;
public float lootWindowHeight = 90;
public float buttonWidth = 40;
public float buttonHeight = 40;
public float closeButtonWidth = 20;
public float closeButtonHeight= 20;
private bool _displayLootWindow = false;
private float _offset = 10;
private const int LOOT_WINDOW_ID = 0;
private Rect _lootWindowRect = new Rect(0,0,0,0);
private Vector2 _lootWindowSlider = Vector2.zero;
public static Chest chest;
// Use this for initialization
void Start () {
}
private void OnEnable() {
Messenger.AddListener("DisplayLoot", DisplayLoot);
Messenger.AddListener("CloseChest", ClearWindow);
}
private void OnDisable() {
Messenger.RemoveListener("DisplayLoot", DisplayLoot);
Messenger.RemoveListener("CloseChest", ClearWindow);
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
GUI.skin = MySkin;
if(_displayLootWindow)
_lootWindowRect = GUI.Window(LOOT_WINDOW_ID, new Rect(_offset, Screen.height - (_offset + lootWindowHeight), Screen.width - (_offset * 2), lootWindowHeight), LootWindow, "Loot Window", "box");
}
private void LootWindow(int id) {
GUI.skin = MySkin;
if(GUI.Button(new Rect(_lootWindowRect.width - _offset * 2, 0, closeButtonWidth, closeButtonHeight), "x", "Close Window Button"))
ClearWindow();
if(chest == null)
return;
_lootWindowSlider = GUI.BeginScrollView(new Rect(_offset * .5f, 15, _lootWindowRect.width - _offset, 70), _lootWindowSlider, new Rect(0, 0, (chest.loot.Count * buttonWidth) + _offset, buttonHeight + _offset));
for(int cnt = 0; cnt < chest.loot.Count; cnt++) {
if(GUI.Button(new Rect(_offset * .5f + (buttonWidth * cnt), _offset, buttonWidth, buttonHeight), chest.loot[cnt].Name)) {
chest.loot.RemoveAt(cnt);
}
}
GUI.EndScrollView();
}
private void DisplayLoot() {
_displayLootWindow = true;
}
private void ClearWindow() {
_displayLootWindow = false;
chest.OnMouseUp();
chest = null;
}
}