- Home /
C# Multiple GUI.Tooltips
Hi everyone, is there a way to give a GUI.Button multiple tooltips? I have three variables I would like to display but I think the GUI.Tooltip only excepts two arguments.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public int someInt;
public string someString;
public float someFloat;
void OnGUI() {
GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", someInt.ToString(), someString,someFloat.ToString()));
GUI.Label(new Rect(10, 40, 100, 40), GUI.tooltip);
}
}
Can you not use line breaks in the tooltip? I haven't tried this, just an idea :) "First Line\\nSecond Line".
No it doesn't work like that. When I tried it the console gave me an error saying it had invalid arguments.
I got it to work by adding pluses ins$$anonymous$$d of commas like this.
GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", someInt.ToString()+ someString+someFloat.ToString()));
But that just adds them together and I want to add space between the variables
try
("Click $$anonymous$$e", someInt.ToString()+" spaces "+someString)
You can also store the string in a temporary string variable and also use string format methods and then pass the string as parameter.
Then add a space:
GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", someInt.ToString()+ " " + someString + " " + someFloat.ToString()));
Answer by phxvyper · Jun 09, 2013 at 11:39 PM
If i understand your question correctly, then the following solution should work.
Replace
GUI.Button(new Rect(10, 10, 100, 20),
new GUIContent("Click me",
someInt.ToString(),
someString,
someFloat.ToString()));
With
GUI.Button(new Rect(10, 10, 100, 20),
new GUIContent("Click me",
someInt.ToString() + "\n" + someString + "\n" + someFloat.ToString()));
You went wrong with your parameters. The only basic function that i think you may have gotten mixed up with is Console.WriteLine in the System library for C#.Net. The reason for me thinking this is because in that method you're allowed to input multiple objects that will be concatenated into the input string.
None of Unity's functions do this with strings. -You have to concatenate manually. The escape value "\\n" creates a newline within the string's environment. (e.g. Environment.NewLine = "\\n").
Answer by InfiniBuzz · Jun 09, 2013 at 11:43 PM
You would go and pass something like
GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", someInt.ToString()+"\n"+someStringOnNewLine+someFloat.ToString()));
you can use these escape modifiers
\n New line
\t Tab
\v Vertical Tab
\b Backspace
\r Carriage return
\f Formfeed
\\ Backslash
\' Single quotation mark
\" Double quotation mark
\d Octal
\xd Hexadecimal
\ud Unicode character
You can also adjust the word wrap.
hope this helps
These escape modifiers sound really useful . Does microsoft have a page on them or is there a site where I could go read more about them?
@DangerousBeans $$anonymous$$SDN ($$anonymous$$icrosoft) has a page for Escape Sequences (Escape $$anonymous$$odifiers):
See this article on the codeproject for more information. You can find lots of atricles about it on the internet.
See phxvypers $$anonymous$$SDN reference link too