HI,
I have a plane that I am trying to drag using touch. It is basically a scoreboard with a little tab off screen that can be swiped on and off the screen whenever needed.
The game is top down - so everything is lying horizontally with an orthographic camera.
Here is my script:
#pragma strict
var speed : float = 30.0;
function Update () {
var clickDetected : boolean;
var touchPosition : Vector3;
// Detect click and calculate touch position
clickDetected = (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began);
touchPosition = Input.GetTouch(0).position;
// Detect mouse left clicks
if (clickDetected) {
// Check if the GameObject is clicked by casting a
// Ray from the main camera to the touched position.
var ray : Ray = Camera.main.ScreenPointToRay
(touchPosition);
var hit : RaycastHit;
// Cast a ray of distance 100, and check if this
// collider is hit.
if (collider.Raycast (ray, hit, 3000.0)) {
// Log a debug message
Debug.Log("Moving the target");
// Move the target forward
transform.Translate(Vector3.up * speed);
} else {
// Clear the debug message
Debug.Log("");
}
}
}
I can touch the object I am trying to drag when the ray hits it. But it barely moves a pixel or two and then won’t budge. I can keep touching it this way and slowly move it, laboriously up the screen - but I’m trying to achieve a nice smooth drag up the screen, with the plane attaching to my finger until I break from the screen.
What am I doing wrong?
Thankyou.