Help!!! How to create a runtime 3D text object?

Hi Pros, I want to create a 3D text created runtime. Basically, my function is to create a 3Dtext when user drag object around. Here is my code, But it does not work!!! Anyone please help me !! much appreciate!!

      void Start () {
           }
           // Update is called once per frame
           void Update () {
                Plane targetPlane = new Plane(transform.up, transform.position);
                //message.text = "";
                foreach (Touch touch in Input.touches) {
                    //Gets the ray at position where the screen is touched
                    Ray ray = Camera.main.ScreenPointToRay(touch.position);
                    //Gets the position of ray along plane
                    float dist = 0.0f;
                    //Intersects ray with the plane. Sets dist to distance along the ray where intersects
                    targetPlane.Raycast(ray, out dist);
                    //Returns point dist along the ray.
                    Vector3 planePoint = ray.GetPoint(dist);
                    //Debug.Log("Point=" + planePoint);
                    //True if finger touch began. If ray intersects collider, set pickedObject to transform of collider object
                    if (touch.phase == TouchPhase.Began) {
                         //Struct used to get info back from a raycast
                         RaycastHit hit = new RaycastHit();
                         if (Physics.Raycast(ray, out hit, 1000)) { //True when Ray intersects colider. If true, hit contains additional info about where collider was hit
                             pickedObject = hit.transform;
                             lastPlanePoint = planePoint;
                         } else {
                             pickedObject = null;
                         }
                    //Move Object when finger moves after object selected.
                    } else if (touch.phase == TouchPhase.Moved) {
                         if (pickedObject != null) {
                             pickedObject.position += planePoint - lastPlanePoint;
                             lastPlanePoint = planePoint;
                         }
                    //Set pickedObject to null after touch ends.
                    } else if (touch.phase == TouchPhase.Ended) {
                        
        				
        				Debug.Log("**************************************");
        //				Instantiate(objText, position, hit.transform.rotation);
        				myText= objText.GetComponent( typeof (TextMesh)) as TextMesh;
        				objText.AddComponent(typeof (MeshRenderer));
        				objText.renderer.material = guiFont.material;
        				objText.transform.position=pickedObject.position;
        				objText.transform.parent = gameObject.transform.parent;
        				myText.text = "HeLLO";
        				objText.transform.localScale = new Vector3(1,1,1);
        				pickedObject = null;
        	
                    }
                }
        		
           }
       
        	}

What part doesn’t work? Is it not being created/displayed, or is it in the wrong spot?

Might be easier if you copied (or used #ifdef UNITY_EDITOR) to make a version using MousePosition, for testing.

Since you will only have 1 of these, could create one inactive TextMesh, and the turn it on/off as needed. That way you won’t have to mess with setting the fontMaterial in code… . Plus you often have to play with a few things to make them look nice.

Unlike GUIText, TextMeshes need to be faced towards you. The default facing is -Z (south) and you can see them from behind, but from a top view they’d be edge-on. May need to set the rotation.