x


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.

more ▼

asked Dec 23 '11 at 10:50 PM

lildevil345 gravatar image

lildevil345
22 6 9 17

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.

Dec 24 '11 at 02:05 AM Apples_mmmmmmmm

thanks for the help!

Dec 27 '11 at 10:28 PM lildevil345
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Dec 28 '11 at 03:29 AM

coolthemanp6p gravatar image

coolthemanp6p
36 8 9 10

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Dec 28 '11 at 01:31 AM

ina gravatar image

ina
3.3k 492 551 603

Ok cool thanks for the help!

Dec 28 '11 at 05:24 AM lildevil345
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3698
x207
x200
x78
x38

asked: Dec 23 '11 at 10:50 PM

Seen: 1088 times

Last Updated: Dec 28 '11 at 06:47 PM