• 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
Question by Ellis · Dec 19, 2012 at 07:52 AM · guibuttontextinventorypopup

Text pop up when mouse over gui button

Hi, I'm working on an inventory for my game and to make stuff take less space on the screen I decided to use pictures instead of text were the items are, now I only whant some text to show up at the mouse when hovering over the item in the inventory (Also show how much of it you got).

Here is some code that I´m using:

The Inventory script:

 var targetScript: Player;
 
 var Inventory = false;
 
 
 var YellowFlowerButton : Texture;
 
 function OnGUI(){
     if(Inventory){
         GUI.Box (Rect (0,0,Screen.height,Screen.width), "Inventory");
             if (GUI.Button (Rect (10,Screen.width/2,Screen.height/2.5,Screen.width/20), YellowFlowerButton)) {
                 if(targetScript.shop == true){
                     if(targetScript.YellowFlower >= 1){
                         targetScript.YellowFlower -= 1;
                         targetScript.YellowFlowers = "Yellow Flowers: " + targetScript.YellowFlower;
                         targetScript.Coin += 2;
                 }
             }
     }
 }


The player script:

 var YellowFlower : int;
 
 
 //ITEM PICKUP
 //YELLOW FLOWERS
 @HideInInspector
 var YellowFlowers = "Yellow Flowers: 0";
 @HideInInspector
 var YellowFlowerPick : GameObject = null;
 @HideInInspector
 var YellowFlowerPick2 = false;
 
 
 function OnTriggerEnter(other : Collider){
 
     //ITEM PICKUP
     //YELLOW FLOWERS
     if(other.tag == "YellowFlower"){
         YellowFlowerPick = other.gameObject;
         YellowFlowerPick2 = true;
     }
     
 }
 
 
 function OnTriggerExit(other : Collider){
     
     //ITEM PICKUP
     //YELLOW FLOWER QUEST
     if(other.tag == "YellowFlower"){
         YellowFlowerPick = null;
         YellowFlowerPick2 = false;
     }
 }
 
 
 function Update(){
     
     //ITEM PICKUP
     
     //YELLOW FLOWERS
     if(YellowFlowerPick != null){
         if(Input.GetButtonDown("Interact")){
             YellowFlower += 1;
             Destroy(YellowFlowerPick);
             YellowFlowerPick2 = false;
             YellowFlowers = "Yellow Flowers: " + YellowFlower;
         }
     }
 }
 
 function OnGUI(){
     
     //ITEM PICKUP
     
     //YELLOW FLOWERS
     if(YellowFlowerPick2 == true){
         GUI.Box (Rect (Screen.height+(Screen.height/17),Screen.width/2-(Screen.width/9),Screen.height/3,Screen.width/30), "\nPress E to take Yellow Flower");
     }
 }


T$$anonymous$$s is only the code that has with the inventory and item pick up to do!

So if someone that is better at coding then I am I could really do with some help! (And I'm really sure there is lots of people out there that is.. xD)

Tnx! :)

//Elis

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Wiki

Answer by KillerStarBunny · Jun 17, 2014 at 03:18 AM

You want a tool tip http://docs.unity3d.com/ScriptReference/GUI-tooltip.html sorry it's just a link, I despise unity's GUI.

Comment

People who like this

0 Show 0 · 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

Answer by SteelArrow21 · Jun 17, 2014 at 03:23 AM

The only t$$anonymous$$ng I could say is that rather than using:

 void OnTriggerEnter ()

you could use:

 void OnMouseOver()

W$$anonymous$$ch you can learn more about here: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html

Also, I'm not sure if you're interested, but there is a t$$anonymous$$rd party tool that can be added to Unity w$$anonymous$$ch makes GUI so much easier. If oyu are interested, you can see it here: http://www.tasharen.com/?page_id=140

And you can see videos on it here: http://cgcookie.com/unity/cgc-courses/getting-started-with-ngui-for-unity/

Comment

People who like this

0 Show 1 · 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 SteelArrow21 · Jun 17, 2014 at 03:40 AM 0
Share

You could do:

 function OnMouseEnter () {
     //display text
 }
 
 function OnMouseOver () {
     //have text follow cursor
     text.transform.localPosition = Input.mousePosition;
     //or something along those lines
 }
 
 function OnMouseExit() {
     //Remove text
 }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Click on a button that is created post start. 0 Answers

New GUI and Inventory problem. 1 Answer

How do I set a GUI button's text using a string from another script? 0 Answers

Find GUI Button and Assign Text 1 Answer

Overlapping GUI Button priority 3 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