Question by
nailyalcin · Mar 09, 2016 at 10:23 PM ·
touchdragging
Drag two Object by Touch At the same time?
Hi, i am trying to drag two object by two finger at the same time but didn't work.
Thanks for help
using UnityEngine;
using System.Collections;
public class DragHandScript6 : MonoBehaviour {
public bool work1,work2;
public Rigidbody2D Player01;
public Rigidbody2D Player02;
public Vector3 targetPos;
void FixedUpdate(){
for(int i = 0; i < Input.touchCount; i++ ) {
Touch theTouch = Input.GetTouch(i);
int fingerId = theTouch.fingerId;
if (work1==true && fingerId == 0)
{
targetPos = Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position);
Player01.MovePosition (targetPos);
if (work2==true && Input.touchCount == 2){
targetPos = Camera.main.ScreenToWorldPoint (Input.GetTouch (1).position);
Player02.MovePosition (targetPos);}
}
if(work2==true && fingerId == 0)
{
if (work1==true && Input.touchCount == 2){
targetPos = Camera.main.ScreenToWorldPoint (Input.GetTouch (1).position);
Player01.MovePosition (targetPos);}
targetPos = Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position);
Player02.MovePosition (targetPos);
}
}
}
public void DragOn1(){
work1 = true;
}
public void DragOff1(){
work1 = false;
}
public void DragOn2(){
work2 = true;
}
public void DragOff2(){
work2 = false;
}
}
adsız.png
(15.1 kB)
adsız2.png
(17.6 kB)
Comment
Your answer
Follow this Question
Related Questions
[SOLVED] When touch and drag objects fast (in android), leave dragging. 1 Answer
Cannot call trigger-event when dragging object via touch 1 Answer
OnDrag is moving all colliders on Touch? (Not on Standalone) 0 Answers
Colliders detect collision too late - touch dragging problem 1 Answer
How to detect Double Tap in Android 12 Answers