- Home /
About Drag Object or Map on mobiles
Hello everybody, i don not understand how to drag map on mobiles,it effect like Game (my singing monster) and how to write code with C# . What to do in code at TouchPhase is Began 、TouchPhase is move and TouchPhase is End . i want to move my camera .i hope give me some suggestions,thanks. my english so bad,so....... thanks!
Answer by Shrikky23 · Aug 16, 2013 at 05:23 AM
if(TouchPhase.Begin) (when you touch the object) - Assign the x,y position of touch position to the (x,y) position of the object that you want to drag.... if(TouchPhase.Moved) do the same , that is the update of the value of object's x,y as the touchposition's x,y ... and then in TouchPhase.End do nothing.
PS:Lets not forget, if yours is a 3D game.Try assigning the z value of 0.... Else check the functions like Camera.ViewportToWorldPoint and other similar features in the camera.
If your camera is Looking at the object, the camera should move along with the object. Else increment/decrement the position of Camera based on the direction of swipe. (hard codin)
Hope this helps
Answer by Yokimato · Aug 14, 2013 at 12:28 PM
You can use Touch.position and translate it to world coordinates. If its touching whatever you need, you then pay attention to TouchPhase "moved" so you can update whatever you're dragging with the new position. Lastly, watch for the end call too, so you can stop dragging completely. Of course you'll want to wire up "begin" to start the process all together.
i got it ,Thanks for your help. i have another questions.how to Smooth transition zoo$$anonymous$$g camera size, i was doing like this :"size += Time.deltaTime * speed",but it not smooth, and how to do ?$$anonymous$$athf.Lerp it does not work
probably best left for a new question. please mark this answer as accepted if it worked please.
Your answer