using UnityEngine; using System.Collections; using System.Linq; using UnityEngine.UI; public class AddItem : MonoBehaviour { public static bool CanAdd = false; Canvas canvas; void Start () { canvas = GameObject.Find("Canvas").gameObject.GetComponent(); TheAddFather = GameObject.Find("TagFather").gameObject; } public GameObject TheADD; private GameObject TheAddFather; void Update () { if (CanAdd) { if (Input.GetMouseButton(0)) { GameObject obj=Instantiate(TheADD)as GameObject; obj.transform.SetParent(TheAddFather.transform); obj.transform.localScale = new Vector3(1, 1, 1); //Vector3 sss = .currentCamera.ScreenToWorldPoint(Input.mousePosition); //obj.transform.position = sss; Vector2 pos; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, canvas.worldCamera, out pos)) { obj.transform.GetComponent().anchoredPosition = pos; } CanAdd = false; } } } }