hello,i am new to unity and i have been relentlessly trying to accomplish this with no success. what i would like to do is this - have an empty gameobject in the scene which is not active, but when the user starts the swipe the gameobject becomes active and automatically snaps to the position of the finger on the screen, and is then constrained to the position of the finger on the screen and follows the swipe regardless of the speed of the swipe or direction. what i have tried so far is this -
instantiate gameobject when the touchphase.moved is started, destroy the gameobject on touchphase.ended, and attach the following script to the prefab:
var speed : float = 0.1;
function Update () {
if (Input.touchCount > 0 &&
Input.GetTouch(0).phase == TouchPhase.Moved) {
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
transform.Translate (touchDeltaPosition.x * speed,
touchDeltaPosition.y * speed, 0);
}
}
but this did not work, what happened is that prefabs were continuously instantiated as long as the touchphase.moved was happening,i only wanted one spawned per swipe motion. additionally the prefab was being spawned at 0,0,0, and not at the touch point (probably a problem with the spawn script).
so then i thought that i could have the gameobject in the scene, and then automatically snap/start at/ move to the position of the finger when the swipe begins. but i am not sure how to get this done. i am using a trail renderer to see where the gameobject is moved during the swipe. i am also using JavaScript. any help with this will certainly be greatly appreciated, i have been trying a variety of different methods, but nothing seems to work, also if someone could point out a better method with scripting i would love to learn from it. thank you in advance.