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 BawsAnimations · Oct 01, 2012 at 01:57 AM · gui3dmouse

Situational GUI / GUI on mouse over?

I am trying to create a game and I want it so that whenever the cursor mouses over certain objects, it brings up a small GUI with information on the object. I have seen others use it. I want to know how to do this, and a basic script if you can please. Please help this is crucial to my game development.

EDIT: I am just trying to get something simple to copy/past and then modify it to my liking once it works.

EDIT: Also any script you provide, do I place it on my targeted object?

Comment
Add comment · Show 1
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 karl_ · Oct 01, 2012 at 04:33 AM 0
Share

Just a heads up, Unity Answers is not meant to be treated as a forum. Asking specific questions is great, but requests for scripts are generally frowned upon.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by karl_ · Oct 01, 2012 at 02:22 AM

Here's a quick example of one way to do this. Create a C# script and name it HoveringText. Then paste this code. Attach script to gameObject.

 public class HoveringText : MonoBehaviour
 {
     void OnGUI()
     {
         Vector2 screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
         Rect pos = new Rect(screenPoint.x, Screen.height - screenPoint.y, 256, 512);
         GUI.Label(pos, "Hovering text here.");    
     }
 }
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 BawsAnimations · Oct 01, 2012 at 03:22 AM

so i replace the "worldObject" with the gameobject that i want to target?

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 BawsAnimations · Oct 01, 2012 at 11:31 PM

This is not what i need, I need a pop up GUI, not a text appearing on the screen. A pop up which can be closed with a button or key press, and the GUI interface should only open up on clicking certain objects.

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 CgShady · Nov 12, 2012 at 08:39 PM

I would suggest using OnMouseDown () to turn a boolean value on, which when on would display a GUI, containing a button to turn the boolean value off again. You need a collider on the object for OnMouseDown to work, and it won't work on mobile (touchscreen) platforms. But that's a start. Also, if you want not be able to open more than one at a time, you'll need a singleton (not the drink :) or a manager of some sort to manage all instances of that script.

Hope this helps.

 public class Popup : MonoBehaviour
 {
     private bool _isOn;
 
     OnMouseDown ()
     {
     _isOn = true;
     }
 
     OnGUI ()
     {
         if GUI.Button ( new Rect ( 10, 10, 50, 20), "close" )
         {
             // your popup content here
             _isOn = false;
         }
     }
 }
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

12 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

Related Questions

Multiple Cars not working 1 Answer

question with gui 2 Answers

Drawing GUI Text using Javascript 2 Answers

mouse displays GUI text when on objects 3 Answers

Does Unity Work With DAZ? 2 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