Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Nov 23, 2013 at 01:27 PM by ozturkcompany for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ozturkcompany · Nov 23, 2013 at 11:38 AM · touchdragcube

How to drag two Cubes by Touch At the same time?

Hi, i am trying to drag two cubes by two finger at the same time but cannot get my code work for it.Could anyone hand me a hand here please, i am stuck at this for few weeks not and tried to solve the problem myself but cannot do it.Here is the code i have on each cube.The code also doesn't work when i first put my finger on somewhere else in the screen and then put my second finger on the cube and try to drag it.Also i cannot drag two cubes at the same time.I am blind here cannot see what i did wrong.

Thank you so much in advance!

 #pragma strict
 var touched : boolean;
 var touchId : int;
  
 function Update () {
  
 for(var i = 0; i < Input.touchCount; ++i) {
  
 if(Input.GetTouch(i).phase == TouchPhase.Began) {
  
 var hit : RaycastHit;
 var ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
  
 if(Physics.Raycast(ray, hit)) {
  
 if(hit.collider == transform.collider) {
  
 touched = true;
 touchId = Input.GetTouch(i).fingerId;
  
 }
  
 }
 
 }
  
 if(Input.GetTouch(touchId).phase == TouchPhase.Ended || Input.GetTouch(touchId).phase == TouchPhase.Canceled) {
  
 touched = false;
 touchId = -1;
  
 }
  
 if(Input.GetTouch(touchId).phase == TouchPhase.Moved && touched == true && Input.GetTouch(touchId).deltaPosition.magnitude > 2) {
  
 transform.Translate(Input.GetTouch(touchId).deltaPosition.x * Time.deltaTime, Input.GetTouch(touchId).deltaPosition.y * Time.deltaTime, 0);
  
 }
  
 }
 
 }
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

16 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

Related Questions

How to instantiate object at touch position? 3 Answers

how can i drag na cube while gameplay? 1 Answer

Box Drag and throw away script for mobile? 0 Answers

How to Touch Drag 3D Objects 2 Answers

Is there a way to optimize Input.GetAxis on windows phone? 1 Answer


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