- Home /
Can I detect a doubleclick on a Gizmo or GameObject?
Simple problem. I want to perform an action when a Gizmo (or the GameObject) is double clicked. Is there any way to watch for that event? I'd rather not build something that listens to the input for clicks and registers the space between them, but that seems like an option. Anything better?
Answer by Tanoshimi2000 · Dec 17, 2015 at 12:49 PM
So I think the closest thing is to use the Event system, specifically the Event.current.button I'm writing my own function to track the doubleclick, and I have it in the
void OnDrawGizmoSelected()
function so it only runs when my gizmo/gameobject is the current selection.
Answer by allenallenallen · Dec 17, 2015 at 11:11 AM
I just randomly came up with a solution and I don't know if it's the best but I'll share it anyway.
Each time a click is registered, you start a timer if a timer isn't already running. The time is set beforehand for the double click time. This timer will stop when the double click window time is gone. Set a boolean saying the timer is no longer running.
Each time a click is registered, you also check if there's a timer running. If a timer is running, call what happens for a double click.
Of course, this is completely reusable. You can call this separate script from elsewhere.
Right. I appreciate the answer. I get that. I've done that before to make double clicks. I was just wondering how to read a click in the editor, or read a double click if it's possible.
I believe the closest thing I can do is write my own double click routine (using timers), and use the Event.current.button
command to read the clicks.
Your answer
Follow this Question
Related Questions
Double-click Detection script on every Game Object? 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Forcing a GameObject to the highest depth (closest to camera) 2 Answers
gameObject.SetActiveRecursively 1 Answer
Rendermode: Cutout not working on gameobject from external asset bundle 2 Answers