- Home /
tap to move object
hello, I wonder how do I get when I give a tap on the screen my object to move up the place? how do I implement the script to drag?
here's the script:
var object : GameObject;
function Update () {
for (var touch : Touch in Input.touches){
var ray = Camera.main.ScreenPointToRay(touch.position);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) {
var cameraTransform = Camera.main.transform.InverseTransformPoint(0, 0, 0);
object.transform.position = Camera.main.ScreenToWorldPoint(new Vector3 (touch.position.x, touch.position.y, cameraTransform.z - 0.5));
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613070729im_/https://answers.unity.com/themes/thub/images/avi.jpg)