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 Eric 11 · Oct 29, 2010 at 09:13 PM · javascriptguibuildings

Making Info Appear when clicking on a building.

So Im working on a small project with some famous buildings, and I wonder how i could make it possible to click at the building and get a GUI text box with facts about it, and maybe a sidescroller if theres a lot of info about a building. But im not that good a scripting so I need some help, Id prefer javascript since i got the most experience with it, hope someone can help me.

/Eric

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

1 Reply

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

Answer by Jesse Anders · Oct 29, 2010 at 11:50 PM

Split the problem into its two constituent parts: detecting when the user has clicked on a building, and displaying info onscreen in response to an event. Once you've solved each problem by itself, it should be fairly straightforward to combine the solutions to get the behavior you described in your post.

For picking, check out the function OnMouseDown(). I've never used it myself, but IINM, this function will be called when the user presses the mouse button while the cursor is over a collider (see the docs for more info). You can test this by attaching a collider to one of your buildings, and then attaching a script that prints out the name of the game object in OnMouseDown(). If everything works correctly, you should get a message in the console when you click on the building.

For displaying the info, I'd start with a simple info box with no scrolling. I don't use Unity's GUI functionality that much, but there should be some controls in there that will do what you want. (There are other ways it could be done as well, such as using the TextMesh component.)

Once you have these two things working, it should be a simple matter of linking them together. One way to link them would be to include the OnMouseDown() and OnGUI() functions in the same script, set a flag to 'true' in OnMouseDown(), and then display the info in OnGUI() whenever the flag is true. (You didn't mention what event causes the info to stop being displayed, so I can't comment directly on that aspect of the problem.)

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 Scroll View Width GUILayout 1 Answer

rts building placement 1 Answer

Unity freezes when changing GUI.Color.a 1 Answer

Limit on GUI Components? 0 Answers

For Loop GUILayout.Label Problems 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