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.


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.)