x


Making an object clickable

I want to make an object that i can right click, i want to click it and have a drop down appear (like in runescape kind of) but i dont know how to go about this, i searched the forums and they said use raycasting (which i've never done). I need a script to help me or someone to explain how to do this if you need more info just ask

more ▼

asked Feb 28 '10 at 05:27 AM

Adam Bruns gravatar image

Adam Bruns
274 24 27 38

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

2 answers: sort voted first

Use OnMouseOver with an object that has a collider (this uses raycasting, but you don't have to program it explicitly):


function OnMouseOver () {
   if (Input.GetMouseButtonDown(1)) {
      // Do right-click stuff here
   }
}

There's OnMouseDown too, where you don't have to check the input, but that's only for left-clicking.

more ▼

answered Feb 28 '10 at 06:27 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

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

erric's answer is correct. just as an additional note i should say. inside the if statement you should set a variable to true and then in GUI do something like this.

function OnGUI ()
{
   if (clicked == true)
{
   //show buttons in a vertical group here
}
}

in mouse leave or other events you should set this variable to false for the GUI to hide it.

more ▼

answered Feb 28 '10 at 02:47 PM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(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:

x5081
x1530
x984
x108

asked: Feb 28 '10 at 05:27 AM

Seen: 3415 times

Last Updated: Feb 28 '10 at 05:27 AM