- Home /
Click and drag an object if holding a button down.
If the user clicks an object normally it performs one function, if they hold a specific key down while clicking then they can drag the object they're clicking on instead.
My current code allows the user to click on an object and perform the first function, and to drag a second object if they repeatedly tap the key while clicking down.
The problem is that the "if (Input.GetKeyDown(KeyCode. ))" is inside "void OnMouseDrag", but I can't figure out how to have "OnMouseDrag" inside an if statement. If that just isn't possible, then how would I go about setting up what I need the code to do?
Any help you can offer or links to relevant places in the documentation would be a great help. Thanks.
$$anonymous$$ak a flag (boolean) which tells you if user is dragging.By using this flag may be you can combine with other Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.) and do necessary operations.
If possible paste your code here.It helps other users to fix the issue immediately. Thank you
Try Input.Get$$anonymous$$ey rather that Get$$anonymous$$eyDown?
@$$anonymous$$GB I don't think Get$$anonymous$$ey will help him, particularly since it sounds like he is already using it for the left mouse button and wants to differentiate between the single click and the held click, am I right in my interpretation?
I'm fairly new myself to Unity, but I've been doing alright. I don't understand everything. I'd like to see your code bc without seeing it I'm taking stabs in the dark....what happens when you attempt to put it inside your void On$$anonymous$$ouseDrag? Perhaps it's in the way you are writing it. I know I've had many, many times something small like a semi-colon screwed everything up and it took me hours to find. ANother thing is, I have had cases where voids I created (I believe they were voids) required parentheses () after the void name when they are called, right before the semicolon. I'm not sure why this is necessary in cases when there is no argument/parameter to use with the void, but....it's something I've noticed.
On the other hand, I could be way off, and I apologize if that was completely unhelpful and irrelevant! Good luck (post your code, man)