- Home /
Interactive GUI?
Hi, im making an RPG and i have some GUI Textures in it. What im wondering is how to make it so the textures can be clicked and do something. Im making a minimap and have a plus and minus texture but dont know how to make them be clickable or zoom the map in and out.
Please help, thanks
ok, another quick question i have been trying for ages but i cant seem to script a window and button grid to open when the player presses "B" as like an inventory so the grid needs to be in front of the window.
You'll want to familiarize yourself more with the GUI scripting.
http://unity3d.com/support/documentation/ScriptReference/GUI.html
For the plus and $$anonymous$$us, you'll want to use the Button function. For the $$anonymous$$i map, you'll probably want to use the ScrollView functions, with a label inside that your map texture will be applied to.
Answer by coolthemanp6p · Dec 28, 2011 at 03:29 AM
If you want to do clicking you would create a couple functions:
function OnMouseDown()
{
}
This makes it so when you click your left mouse button.
function OnMouseEnter()
{
}
This makes it when you hover your mouse over the texture.
function OnMouseUp()
{
}
This makes it when you release your left mouse button.
OnMouseExit()
{
}
When you your mouse leaves the area of your GUI texture this happens.
With these you can create fully operating buttons.
Answer by ina · Dec 28, 2011 at 01:31 AM
The button syntax took me a while to figure out at first too. The key is that the Rect defines the coordinates of the button in terms of the pixel coordaintes and not the screen coordinates.
var texGraphic:Texture2D; // drag and drop your button graphic here in inspector
function OnGUI(){ if(GUI.Button( Rect(10,10,100,100) , texGraphic)){ Debug.Log("Clicked"); } }
As for making a minimap, you can use raycasthit to determine the screen coordinate hit, and then calculate the location of the minimap clicked on.
Zooming in and out could be as simple as switching the map images to different graphics depending on zoom distance.
Your answer
Follow this Question
Related Questions
Map Camera 1 Answer
help with minimap 1 Answer
how make a for loop that makes GUI boxes ? 1 Answer
revealing a Mini map, how to?? 1 Answer