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?
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.
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;
}
}
}