Display two tooltips?

I’m trying to create a dual gui tooltip for hovering over a single button. I am able to do this with two different positioned gui labels but I am unsure how to display different information on each one. Anyone know how to do this? I want to display infro from both my inventory list and equiped item array.

Why not set two texts to display and make a random one play each time the tip is turned on.

I’m a little confused. I’ll post my code and explain.

	for(var x = 0; x < MainInventory.Count; x++) {
	
		if(GUI.Button(Rect(Screen.width/2, Screen.height/2 + ( 20 * x), 100, 20), GUIContent ( MainInventory[x].Name, 
		"Stamina: " + MainInventory[x].Stamina + "\n" +
		"Power: " + MainInventory[x].Power + "\n" +
		"Attack Speed: " + MainInventory[x].attackSpeed + "\n" +
		"Rarity: " + MainInventory[x].rarity ))) {

		}
                //This one displays contents of the above GUIContent on hover over button
		GUI.Label(Rect(Screen.width/2 + 150, Screen.height/2 + ( 20 * x), 300, 300), GUI.tooltip);
		//I want this text to display variables from a different GUIContent when hovering over the same button
		GUI.Label(Rect(Screen.width/2 + 350, Screen.height/2 + ( 20 * x), 300, 300), GUI.tooltip);
	}

As far as I know and worked with it you only can use one tooltip at a time. If you use two Labels (or whatever) to display tooltips they will get mixed up and i think one overrides the other one. I noticed that you can have another tooltip in a Window that needs a new GUIContent from that window and ignores the tooltips from outside, but dunno if this is any helpful ^^

I think you want to have some compare function while viewing the inventory item and at the same time show the equipped item, right? I would simply suggest to create your two labels and add a string variable to both, like GUI.Label(new Rect…), invItem); and GUI.Label…), equipItem);. Then just add the information to the right strings.

To save some coding you could have the invItem string replaced by the GUI.tooltip and the equipItem will stay, now you just need a function that gets the mouse Input, and copy the Rect from the Buttons (with size and position) you have to check when the mouse is within the rect of your buttons and then if rect XYZ contains.mouseInput = true show the info from the equiped item.

I hope you get a little bit of what I am talking about XD

I was hoping I could keep it so I could display the two tooltips how it’s setup now but give the second one a different GUIContent to display. I’m still confused if this is possible or not. Is there any other way to activate a piece of code while hovering over the button? What I’m trying to do is an mmorpg style where you can hover over an inventory item and view the stats of both that item compared to the equipped item.

There are a few ways to do it. The easy way to do it is to compare the tooltip to the current tooltip for a match. Then open a gui or two with the bool.

Place under the GUIContent

if(GUI.tooltip=="someTooltip") {
  // hold a bool true
}
else {
  // Make the bool false.
}

This is more understandable. So my Gui Labels won’t need the GUI.tooltip part? or? I’m mainly confused about the “someTooltip” and where it gets that name from, I’m guessing I have to give me GUIContent some kind of var name?

The GUIContent would cover the inventory item slot. If whatever key word or number you use for the tooltip matches the GUI.tooltip in the condition(Basic check itself) then true the bool opening any GUI that is wrapped by the bool. Turn the bools off with else.

Ofc trying to place an GUIContent element over every inventory slot would take a lot of code, but there is an easy way to do it. When creating your loop to display a grid of inv slots you can then insert the GUIContent one time in the loop.(One Line) You can even push important info through the looped eg GUI.label with the GUIContent eg item stack numbers etc.

Now I hope I haven’t lost u lol, By running the index through the GUIContent you can check what ever inv slot you’re hovering over. (Basic Tt System)

If you need I can give a example or two in Js.

This is the method I ment, hope this code is more clear than my explanation skills lol :smile:

Basically you have one tooltip frame and a normal Content like Label, Box, etc. and display the other information there instead.
You can also use a tooltip for each window (but it wouldn’t change anythign for u as the tooltip will only be shown when you hover over a button). There’s some focus issues with the windows so it only works if you haven’t selected on or selected the character window. There should a workaround for this, or you simply just use 1 window to show all and include something like tabs or so.

using UnityEngine;
using System.Collections;

public class InventoryCompare : MonoBehaviour
{
	bool hoverItem = false;
	
	void OnGUI()
	{
		GUI.Window(0, new Rect(10,10,150,200),InventoryWindow, "Inventory");
		
		GUI.Window(1, new Rect(170,10,150,200),CharacterWindow, "Character");
	}
	
	void CharacterWindow(int WinID)
	{
		GUI.Button(new Rect(10,30,100,25), "Equiped Item");
		
		string equipedItemTooltip = "equiped item stats";
		
		if(hoverItem)
			GUI.Box(new Rect(10,80,130,110), equipedItemTooltip);
	}
	
	void InventoryWindow(int WinID)
	{
		GUI.Button(new Rect(10,30,100,25), new GUIContent("Inventory Item", "tooltip from\n equiped Item"));
		
		if(GUI.tooltip != "")
		{
			hoverItem = true;
		}
		else
		{
			hoverItem = false;
		}
		
		GUI.Box(new Rect(10,80,130,110), GUI.tooltip);
	}
}

It’s a lot easier to visualize what you’re trying to say with code. I still am a little lost :confused: You can checkout my code I wrote above for how I have everything setup.

This makes a lot more sense. So there’s no way to set this up without using seperate functions?

Well you could use the same function for it, the only thing you have to remember is that you only can use “1” tooltip at a time, so the other field needs some if-checks for the tooltip so you know when it will be shown. Then simply display the Label/Box with the other information.

I just used two windows and seperate functions to simulate a basic MMO Layout, mostly you’ll have seperate windows for inventory and the character window, but you can just use one window or only a Label or whatever you want. I think you get what i mean and how you could edit the script to make use of it like you want.

Simple version could look like this:

void CompareItems()
{
	GUI.Button(new Rect(10,30,100,25), new GUIContent("Inventory Item", "tooltip from\n equiped Item"));

	// use strings to set your wanted text for each item you want to compare
	string tooltip2 = "equiped item info goes here";

	// check if the tooltip shows up	
	if(GUI.tooltip != "")
		GUI.Label(new Rect(10,60,100,100), tooltip2);
 
	GUI.Box(new Rect(10,80,130,110), GUI.tooltip);		// will show the tooltips

	// as a bonus you could place the tooltips at mouse cursor position and dock the equip item tooltip to the first one
}

Still need help? Just incase u do

Start by adding this line and local var right under the loop and above the button.

var invIndex = x;
GUI.Label(new Rect(Screen.width/2, Screen.height/2 + ( 20 * x), 100, 20), GUIContent("Label" + " i = " + x, invIndex.ToString()));

Step Two in a minute lol. now The button as a label. Just click button location and look at the console to see the correct index being printed out.

if((GUI.Button( new Rect(Screen.width/2, Screen.height/2 + ( 20 * x), 100, 20),"", GUIStyle("label")))) {
 // New button Section. Cause im a label im clear but work like a button
 print("proof im working  MyIndexnum = " + invIndex.ToString());
}

Try these lines first to see if you like and we will go on. Just these lines show the basic tricks for getting a tip over a loop.

If you use a double loop (Double Bird Nest) you can create a grid of columns and rows, but I’m sure u know that.

That worked perfect! Thanks for taking the time to figure it out!

@Black Mantis Thanks for the help as well!