Touch Follow 3d.

I’m struggling right now for the control of my game all I can see in the youtube and into the unity forum is touch follow of 2D. Help me I’m so depress for this control I can’t fix this. The 3d gameobject must follow my finger when I touch it in the screen.

using UnityEngine;
using System.Collections;
public class TouchMove : MonoBehaviour {
public float speed = 0.02f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0) {
// The screen has been touched so store the touch
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
// If the finger is on the screen, move the object smoothly to the touch position
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y,10));
transform.position = Vector3.Lerp(transform.position, touchPosition, Time.deltaTime);
}
}
}
}

Aaaah, now I see your problem. In asking questions, you really need to spell out the issue since we don’t see your action. The current code is moving the object in the 3D space. I’m assuming you have an angled camera with an object that is setting on a plane parallel to the XZ plane. The solution is to use a Raycast(). I like to use Unity’s mathematical Plane class to solve this problem. Here is an untested rewrite of your code to use a the Plane class to solve your problem:

using UnityEngine;
using System.Collections;
public class TouchMove : MonoBehaviour {
	public float speed = 0.02f;

	void Update () {
		if (Input.touchCount > 0) {
			// The screen has been touched so store the touch
			Touch touch = Input.GetTouch(0);
			if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
				// If the finger is on the screen, move the object smoothly to the touch position
				Plane plane = new Plane(Vector3.up, transform.position);
				Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
				float dist;
				if (plane.Raycast (ray, out dist)) {
					transform.position = ray.GetPoint (dist);
				}
			}
		}
	}
}