- Home /
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
Answer by Eric5h5 · Feb 28, 2010 at 06:27 AM
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.
Answer by Ashkan_gc · Feb 28, 2010 at 02:47 PM
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.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
how can i Find an object height, while click on that object? 1 Answer
Calling function in a script based on raycast hit 1 Answer
Getting a character to fly(follow cursor in 2D) in Unity4.3 0 Answers
I want to click on my screen and make my character move there, having trouble with raycasts. 1 Answer