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 Art Condelles · Feb 26, 2011 at 10:39 PM · mousepositionmouseovertooltip

Tooltip and mouse position

Hi all I had actually posted to another answer and mean to start a question of my own, I am very new to scripting I( am a game artist looking to get into the intricacies of scripting and boought unity several years back when you had to purchase an indie license, I am now starting on making a game and I know that my scripting is very basic but I had taken some examples from here to try and create a tooltip that appears at the mouse when you hover over the object, in this case a button. However when the moueover occurs the tooltip is at the bottom of the screen, I learn better if I know what was wrong could anyone explain to me why my code isnt working and help me get it right? Its intimidatying being new to this type of thing and I hope it does not seem like a dumb question...Here is the code

var mousePos: Vector3 = Input.mousePosition;

function OnGUI () { if (GUI.Button (Rect (10, 10, 100, 50), GUIContent("New Game", "Start a New Game"))) {

     Application.LoadLevel (1);

     }
     GUI.Label (Rect (mousePos.x, mousePos.y - 100, 100, 20), GUI.tooltip);

}

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

4 Replies

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

Answer by Eric5h5 · Feb 27, 2011 at 12:44 AM

OnGUI code should use Event.current.mousePosition, not Input.mousePosition (using Input results in screen space coords, not GUI coords). You can't just declare it once, you need to get the position every frame, so it has do be done in OnGUI.

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
1

Answer by Hei · Feb 27, 2011 at 12:20 AM

You can use this script

var mousePos: Vector2;

function Update () { mousePos = Input.mousePosition; }

function OnGUI () { if (GUI.Button (Rect (10, 10, 100, 50), GUIContent("New Game", "Start a New Game"))) { Application.LoadLevel (1); } GUI.Label (Rect (mousePos.x, mousePos.y -100, 100, 20), GUI.tooltip); }

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 Art Condelles · Mar 03, 2011 at 12:32 AM

Hi Erich thanks for your answer I am trying via your advice to complete the script and for aome reason now that I am calling the mousePosition in the OnGUI function it is not showing this is the current code I am using thanks again....

var mousePos: Vector2 ;

 function OnGUI () {

         mousePos = Event.current.mousePosition;

         if (GUI.Button (Rect (10, 10, 100, 50), GUIContent("New Game", "Start a New Game")))
         {
         Application.LoadLevel (1);
         }
         GUI.Label (Rect (mousePos.x, mousePos.y - 100, 100, 20), GUI.tooltip);
 }

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 Art Condelles · Mar 03, 2011 at 12:59 AM

Update I changed the structure a bit Erich thanks to your help its seems to be working, thank you to all who answered I really appreciate it !! PS I tried to login to say your answer helped me but it wont let me login under any of my IDs....weird...

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

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

No one has followed this question yet.

Related Questions

Setting ToolTip to Above Mouse Position 5 Answers

Additional information on mouseover in the inspector 4 Answers

Mouseover using GUI.Tooltip 0 Answers

Mouse position in camera view area 1 Answer

GUI Texture follow the mouse 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