- Home /
Question by
wl01973167 · Oct 01, 2015 at 12:06 PM ·
dragdraggingtouchphase
Unity 2D touch drag on Android
Hello, I'm a begginer in Unity. I want to drag object in all places. Actually i have similarity program. But this program is not what I want, The program is i touch screen everywhere the object will be drag. My ideal is when i touch the object then drag. Thank you.
using UnityEngine;
using System.Collections;
public class NewPe : MonoBehaviour
{
float distance = 10;
void Start()
{
}
void Update()
{
if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Moved)
{
Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
Vector3 objPositon = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = objPositon;
}
}
}
Comment