Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Ochreous · Jun 09, 2013 at 10:39 PM · c#guitooltip

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);
     }
 }
Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image numberkruncher · Jun 09, 2013 at 10:42 PM 0
Share

Can you not use line breaks in the tooltip? I haven't tried this, just an idea :) "First Line\\nSecond Line".

avatar image Ochreous · Jun 09, 2013 at 10:49 PM 0
Share

No it doesn't work like that. When I tried it the console gave me an error saying it had invalid arguments.

avatar image Ochreous · Jun 09, 2013 at 11:00 PM 0
Share

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

avatar image InfiniBuzz · Jun 09, 2013 at 11:08 PM 0
Share

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.

avatar image robertbu · Jun 09, 2013 at 11:08 PM 0
Share

Then add a space:

GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", someInt.ToString()+ " " + someString + " " + someFloat.ToString()));

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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").

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ochreous · Jun 09, 2013 at 11:48 PM 0
Share

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?

avatar image phxvyper · Jun 09, 2013 at 11:54 PM 0
Share

@DangerousBeans $$anonymous$$SDN ($$anonymous$$icrosoft) has a page for Escape Sequences (Escape $$anonymous$$odifiers):

http://msdn.microsoft.com/en-us/library/h21280bw.aspx

avatar image InfiniBuzz · Jun 10, 2013 at 12:00 AM 0
Share

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

avatar image InfiniBuzz · Jun 10, 2013 at 12:08 AM 2
Share

there is no need to vote this down.. ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# GUI.Tooltip If Statement 2 Answers

FPS keep a loadout 0 Answers

How to increase space between two things with GUILayout.BeginHorizontal C# 1 Answer

How to dynamically change the text in Unity(Augmented Reality + NYARtoolkit(C#)) ? 0 Answers

C# How to Drag and Scale with Mouse Window 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges