Hi , I’m trying to move two objects at the same time each with a different finger. I am able to move just one at a time. Can somebody help me and point me to the right direction please? Thank you very much.
This is my code:
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
public class moveCircles : MonoBehaviour {
[SerializeField]
private Transform aPointer;
//Target object that will be rotating
private Transform targetObj;
//offsets to calculate right position
private float dummyOffset;
private float targetOffset;
//flag of mouse status. "True" means mouse be just pointed.
private bool mouseIsUp = true;
//Target obj that will be spined.
private Transform preObj;
public List<Transform> targetObjects = new List <Transform> ();
int maxTouch = 2;
void Update () {
var nbTouches = Input.touchCount;
if (nbTouches > 0)
{
Touch myTouch = Input.GetTouch (0);
Touch [] myTouches = Input.touches;
for(var i = 0; i < Input.touchCount; i++)
{
//int fingerId = myTouch.fingerId;
var ray = Camera.main.ScreenPointToRay (myTouches*.position);*
-
RaycastHit hit;* -
// If the Raycast hits circle 1 or 2* -
if (Physics.Raycast (ray, out hit) && ((hit.transform.name == "circle1") || (hit.transform.name == "circle2"))) {* -
//Set target object and pre objec* -
if ((hit.transform.name == "circle1") || (hit.transform.name == "circle2")) {* -
targetObj = hit.transform;* -
}* -
aPointer.LookAt (hit.point);* -
// If this is the initial mouse press: * -
if (mouseIsUp && (hit.transform.tag != "bkg")) {* -
// set the angles of the pointer and the targetObj:* -
dummyOffset = aPointer.eulerAngles.y;* -
targetOffset = targetObj.eulerAngles.y;* -
mouseIsUp = false;* -
//Set Current Object* -
preObj = targetObj;* -
} else if (preObj != null) {* -
//In the case when circle1 or circle2 was pointed and is still pointed and moved.* -
if (preObj.name == targetObj.name && mouseIsUp == false) {* -
//Spinning!* -
targetObj.eulerAngles = new Vector3 (0.0f, targetOffset + (aPointer.eulerAngles.y - dummyOffset), 0.0f);* -
}* -
}* -
}* -
}* -
}else if (!mouseIsUp){* -
mouseIsUp = true;* -
}* -
}*
}