I'm making a tutorial for my game and need to test for a left mouse button drag I'm using.... Code (csharp): if (Input.GetMouseButton(0) EventType.mouseDrag) { blah } But blah runs on MouseButtonDown - with no mouse drag what gives? Cheers,
I'm guessing drag just checks if the button is held down, not whether you are actually dragging? Could you check distance manually by storing the position on click, and say dragDistance = currentPosition - clickPosition. if dragDistance > x doBlah() That might also allow you to make sure people drag for a while before it completes.
thanks, that is what it looks like. If this is so... then there is no need for an event that does the same thing as mouse down. I figured that at least some mouse delta would be needed to trigger the event but no. All that is needed is mouse down. :roll: Cheers,
I mean, even if it were based on movement, one could make an argument that your mouse is always moving... Otherwise you'd have to define some arbitrary minimum delta, which would also seem sort of pointless. Then, if it stopped 'moving' in the middle of a drag, would that stop the drag function? I think that would be even worse. Although, I see your point with Event.
NullReferenceException: Object reference not set to an instance of an object @ --> if ( Event.current.type == EventType.mouseDrag ){ blah(); } BTW - MouseDrag didn't compile - but mouseDrag did EDIT -- Only works with GUI's - I guess. Other than OnMouseDrag (which needs a collider) there is no api for mouseDrag events -- will code it myself. Cheers,
It's a simple test for ANY mouseDrag event - not over a GUI or collider. I'm making a tutorial to teach the game skills. Cheers,
Code (csharp): if ( Input.GetMouseButtonDown ( 0 ) Input.GetAxis("Mouse X") != 0 ){ print ("---> " +Input.GetAxis("Mouse X")); } Now what's wrong with this logic?
Event.current is only valid inside an OnGUI function - that's why I asked In your script you are checking if the mouse has a non-zero X position, not if it has moved.
Silly me -- I needed Input.mouseButton NOT Input.mouseButtonDown I wanted the test to keep testing while the mouse button was down not just on the first frame down. Cheers,