- Home /
tooltip on guibutton
i have a guibutton with texture2d
if (GUI.Button(Rect(TargetX+20,TargetY+15,55,70),Resources.Load("item/ring",Texture2D))) {
BS_Skill = 0;}`
how can i make a tooltip when the mouse over the button. i tried with guicontent but system told me guicontent supports (string,string) not (texture2d,string)
Answer by Bunny83 · Mar 28, 2011 at 10:19 PM
You can use a Texure in GUIContent. Just take a look into the scripting reference.
From documentation:
static function GUIContent (image : Texture, tooltip : string) : GUIContent
Since Texture2D is derived from Texture you can assign it to image. You could add your GUIContent-version to your question, maybe there's something wrong with your syntax. You can edit your question at any time.
edit
var ringTexture : Texture2D;
function Start() { ringTexture = Resources.Load("item/ring",Texture2D); }
function OnGUI() { if (GUI.Button (Rect (10,10,100,20), GUIContent (ringTexture,"Tooltip"))) { //... } }
You could also drag and drop the texture onto the variable in the inspector. That way you don't need to place it in the resources folder and don't need to load it manually.
icon : Texture; GUI.Button (Rect (10,10,100,20), GUIContent (icon, "This is the tooltip")
is working but ;
GUI.Button (Rect (10,10,100,20), GUIContent (Resources.Load(item,Texture), "This is the tooltip") is not working ?
why
That's the problem of JS and it's implicit typing. Resources.Load returns a reference of type Object. It have to be casted to the right type. In most cases it happens automatically but in this case Unity don't know to what type it should cast because there are more than one versions of the GUIContent-constructor. You even shouldn't use Resources.Load in Update (or OnFUI). Load the texture once at start and save it in a variable. I will edit my answer.
Answer by Justin Warner · Mar 28, 2011 at 09:17 PM
http://unity3d.com/support/documentation/ScriptReference/GUI-tooltip.html
In case you missed it...
function OnGUI () { // Make a button using a custom GUIContent parameter to pass in the tooltip. GUI.Button (Rect (10,10,100,20), GUIContent ("Click me", "This is the tooltip"));
// Display the tooltip from the element that has mouseover or keyboard focus
GUI.Label (Rect (10,40,100,40), GUI.tooltip);
}
And that's an example...
http://unity3d.com/support/documentation/ScriptReference/ScriptRefImages/GUITooltip.png
Good luck!
And I edited to make the code you had coded... Just highlight your code, and then push the 10101 button, =). For future posts, and thanks!
Your answer