- Home /
Generating tooltips for multiple buttons.
Hi, I'm trying to get a loot container system working for a roguelike i'm working on. So far i've got a window and buttons generated for each item added to a lootList. Player clicks the button and the items are transferred to their inventory. This all works. Now i'm trying to get a tooltip with the item name to appear when the player mouses over the button. I've got the basics working but the problem i'm having is that when I mouse over the first item, it generates a tooltip for every item. The second item generates a tooltip for all but the first item. The third item generates a tooltip for all but the first two, etc. Here's my code:
private void LootWindow(int id) {
if(GUI.Button (new Rect(lootWindowRect.width - 30,0, closeButtonWidth,closeButtonHeight), "x")){
ClearWindow();
}
//GameObject deadEnemy = GameObject.FindGameObjectWithTag("DeadEnemy");
lootWindowSlider = GUI.BeginScrollView(new Rect(5, 15, lootWindowRect.width - 10, 70),lootWindowSlider,new Rect(0,0,lootItems.Count * buttonWidth, 5 * offset));
for(int cnt = 0; cnt < lootItems.Count; cnt++){
if(GUI.Button(new Rect(buttonWidth * cnt, 5, buttonWidth, buttonHeight), new GUIContent (lootItems[cnt].texture, lootItems[cnt].name))){
playerObject.GetComponent<Player>().inventory.Add(lootItems[cnt]);
Debug.Log(lootItems[cnt].name + " added to inventory");
lootItems.Remove(lootItems[cnt]);
}
GUI.Label(new Rect(buttonWidth * cnt,10,100,40), GUI.tooltip);
}
Anyone have any tips for how I could make this work better?
Answer by $$anonymous$$ · May 16, 2013 at 08:48 PM
Add GUI.tooltip = null;
after GUI.Label(new Rect(buttonWidth * cnt,10,100,40), GUI.tooltip);