Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NeroValentin · May 04, 2017 at 09:56 AM · unity 5mousedragif statementupdate function

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sandeepsmartest · May 04, 2017 at 10:48 AM 0
Share

$$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

avatar image _MGB_ · May 04, 2017 at 11:11 AM 0
Share

Try Input.Get$$anonymous$$ey rather that Get$$anonymous$$eyDown?

avatar image dhar174 · May 04, 2017 at 11:50 AM 0
Share

@$$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)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Drag object with mouse in diagonal direction 1 Answer

Instantiate and Scale with Mouse Click. 1 Answer

How To Drag any Cube Using Mouse Click and Moved Only 1 Unit?? 2 Answers

Camera orbit and object following 1 Answer

dragging camera with mouse results in camera jumping., 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges