- Home /
Question by
refsus · Aug 12, 2014 at 08:40 AM ·
gameobjectcollidertouch
Move 2 gameObject with touch at the same time
I want to move two gameobject with touch at the same time (with same tag), but I can only move one of the gameobject, how can I move these gameobject at the same time?
using UnityEngine;
using System.Collections;
public class TouchDetector : MonoBehaviour
{
GameObject Skate1;
GameObject Skate2;
RaycastHit Handle1;
Vector3 ObsPos1;
Vector3 MousePos1;
void Start()
{
Skate1 = GameObject.Find("Skate1");
Skate2 = GameObject.Find("Skate2");
}
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0)
{
for (int i = 0; i < Input.touchCount;i++ )
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
if (hitInfo.collider.gameObject.tag == "Selectable")
{
Handle1 = hitInfo;
ObsPos1 = hitInfo.transform.position;
MousePos1 = Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position);
}
}
}
if (touch.phase == TouchPhase.Moved)
{
Vector3 MovePos = Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position);
Vector3 Distance = new Vector3(MousePos1.x - MovePos.x, 0, MousePos1.z - MovePos.z);
Handle1.transform.position = new Vector3(ObsPos1.x - Distance.x, 0, ObsPos1.z - Distance.z);
}
}
}
}
}
}
thanks for the response
Comment