|
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.
(comments are locked)
|
|
If you want to do clicking you would create a couple functions: This makes it so when you click your left mouse button. This makes it when you hover your mouse over the texture. This makes it when you release your left mouse button. When you your mouse leaves the area of your GUI texture this happens. With these you can create fully operating buttons.
(comments are locked)
|
|
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. Ok cool thanks for the help!
Dec 28 '11 at 05:24 AM
lildevil345
(comments are locked)
|

You'll want to familiarize yourself more with the GUI scripting.
http://unity3d.com/support/documentation/ScriptReference/GUI.html
For the plus and minus, you'll want to use the Button function. For the mini map, you'll probably want to use the ScrollView functions, with a label inside that your map texture will be applied to.
thanks for the help!