Unity2D add an Object on the mousePositon


AS follows is my Code,I do not know what is wrong about it ? I want to add Test Object on the mouse position, but the code is not achieve. (Unity2D).
please help me,OK ?

this is my code:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TestCoordinate : MonoBehaviour {
Vector3 screenPosition,mousePositionOnScreen,mousePositionInWorld;
// Use this for initialization
void Start () {


// Update is called once per frame
void Update () {

	screenPosition = Camera.main.WorldToScreenPoint(transform.position);  
	mousePositionOnScreen = Input.mousePosition;

	mousePositionOnScreen.x = Input.mousePosition.x;
	mousePositionOnScreen.y = Input.mousePosition.y;
	mousePositionOnScreen.z = screenPosition.z;

	mousePositionInWorld =  Camera.main.ScreenToWorldPoint(mousePositionOnScreen);  

	if (Input .GetMouseButtonDown(0)) {  
		AddMeasureText (mousePositionInWorld);

public void  AddMeasureText(Vector3 hh){

	GameObject go = new GameObject("AddSizeText", typeof(Text));  
	var text = go.GetComponent<Text>();  
	text.raycastTarget = false;  
	text.text = "hello world";
	text.font = Font.CreateDynamicFontFromOSFont("Arial",70);
	text.fontSize = 70;
	text.color = Color.yellow;
	RectTransform rt = go.GetComponent<RectTransform>();              
	rt.sizeDelta = new Vector2(200, 100);
	rt.transform.position = hh;
	rt.transform.Rotate(new Vector3(0, 0,0));  
	GameObject UIRoot = GameObject.FindWithTag ("UIRoot");



I believe this is all you need… I hope. (Haven’t done Unity for a bit). I didn’t check your AddMeasureText as you didn’t describe what it is supposed to do but you should be able to figure it out now.

void Update () {
  // Input.mousePosition gives you screen position. You need to convert to world
  mousePositionInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  // Since you are in Unity2D, you don't need Z.  Set z to whatever your other objects are.  
  // Typically 0
 mousePositionInWorld.z = 0;
 if (Input .GetMouseButtonDown(0)) {  
   AddMeasureText (mousePositionInWorld);