- Home /
Mouse click in edit mode. ✱✺✸❁
I have a script attached to a GameObject which starts with ExecuteInEditMode() and in which I am using Update() and OnDrawGizmos(). I have a var ev and in OnDrawGizmos I have if (Event.current) ev = Event.current. In Update() there is if (ev.type == EventType.mouseDown). However, the event type is always "Repaint". What is the problem?
Answer by whydoidoit · Jul 15, 2012 at 02:37 PM
Event.current happens inside OnGUI code - you will never get it to be anything useful in Update. You want to be testing Input.GetMouseDown(0) in Update.
Input.Get$$anonymous$$ouseDown(0) always returns false and "function OnSceneGUI () { if (Event.current) ev = Event.current;}" is never called. What is the problem?
Input.Get$$anonymous$$ouseDown(0) will always be false inside OnGUI code. The rest of your comment looks odd - are you inheriting from EditorWindow or something to get you that code?
I mean that I tried both; using "if (Input.Get$$anonymous$$ouseDown(0))" ins$$anonymous$$d of "if (ev.type == EventType.$$anonymous$$ouseDown)" inside Update(), and adding the function "function OnSceneGUI () { if (Event.current) ev = Event.current;}" and then "if (ev.type == EventType.$$anonymous$$ouseDown)" inside Update(), but neither works. I then found out that Input only works at runtime, so the only option is using Event. I need the event data in Update(), but since it does not work there, I currently store it into a global variable in OnDrawGizmos(). The problem is that the event type is always "Repaint".