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
0
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");
     }
 }


This 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
Add comment
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
0
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
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
0

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

The only thing I could say is that rather than using:

 void OnTriggerEnter ()

you could use:

 void OnMouseOver()

Which 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 third party tool that can be added to Unity which 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
Add comment · 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 On$$anonymous$$ouseEnter () {
     //display text
 }
 
 function On$$anonymous$$ouseOver () {
     //have text follow cursor
     text.transform.localPosition = Input.mousePosition;
     //or something along those lines
 }
 
 function On$$anonymous$$ouseExit() {
     //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.

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

Gui Button Solid 2 Answers

GUI & GUI Text Disappear When Publishing 6 Answers

Change Text of GUI Button from Script 2 Answers

proper inventory system issue.. 1 Answer

how to change a gui button texture 1 Answer


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