• 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 Der_Kevin · Apr 20, 2016 at 08:21 AM · onmousedown

void OnMouseDown for mobile?

hey! i wanted to use this snippet: http://pastebin.com/Mn6sx1MC but somehow it doesent work on a phone - but perfect in a editor. i think that OnMouseDown at line 30 is causing the problem. so this line:

 void OnMouseDown(){
         beingDragged = true;
     }
     void OnMouseUp(){
         beingDragged = false;
         transform.position = oldPosition; // place on the last valid position
         _intersecting = 0; // stationary block do not intersect anymore
         TintRed(_intersecting); // set the tint one last time
     }

how do i have to change this to make this work on a phone?

Comment
Add comment
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

6 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Nikunj-Kareliya · Apr 20, 2016 at 09:01 AM

Other alternative is to use methods of Input class inside the Update().

 void Update () {
         if(Input.GetMouseButtonDown(0)) {
             beingDragged = true;    
         }
         else if (Input.GetMouseButtonUp (0)) {
             beingDragged = false;
             transform.position = oldPosition; // place on the last valid position
             _intersecting = 0; // stationary block do not intersect anymore
             TintRed(_intersecting); // set the tint one last time
         }
 
 }

Comment
Add comment · Show 2 · Share
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 Der_Kevin · Apr 20, 2016 at 09:24 AM 0
Share

ok, thanks. that sounds pretty reasonable. but somehow my drag function is acting weird now: http://imgur.com/a/cQGpU

the second gif is how it was before - but not working on mobile. the first how it is after the code changes

avatar image Nikunj-Kareliya · Apr 29, 2016 at 01:01 PM 0
Share
 // Suppsoe it is perspective camera view
     void Update () {
         if (Input.Get$$anonymous$$ouseButton(0)) {
                             
             // Convert mouse position into world position
             // make sure you have passed the distance between object and camera as a 3rd parameter of vector3() method
             Vector3 worldPos = mainCamera.ScreenToWorldPoint (new Vector3(Input.mousePosition.x, Input.mousePosition.y, 20f));
 
             Vector3 tmpPos = cloneBasket.transform.position;
             // Drag only in X axis
             tmpPos.x = $$anonymous$$athf.$$anonymous$$oveTowards (tmpPos.x, worldPos.x, Time.deltaTime * 5);
             // Restriction of object in X axis
             tmpPos.x = $$anonymous$$athf.Clamp (tmpPos.x, 1502.8f, 1507);
             cloneBasket.transform.position = tmpPos;
         }
     }
  • ‹
  • 1
  • 2

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnDestroy collision detect 4 Answers

Stop a Lerp from looping 3 Answers

OnMouseUp error 0 Answers

iOS multiTouch / release - Strange problem 0 Answers

OnMouseDown If-statement Question 3 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