Question by
elliot_unity · Aug 11, 2017 at 11:04 PM ·
c#touchmobile devices
dragging multiple game objects simultaneously (mobile)
I am attempting to drag two separate game objects simultaneously using multi touch, although the code i have written does not seem to work:
private void Update() {
foreach (Touch touch in Input.touches)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject == gameObject)
{
Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
transform.position = new Vector2(transform.position.x, touchPosition.y);
}
}
}
The code is attached to both objects which I wish to drag.
Research I conducted proved unsuccessful. Please advise, thanks!
Comment