先使用 Camera.main.WorldToScreenPoint,将世界坐标转换为屏幕坐标,再使用ScreenPointToLocalPointInRectangle(),来计算转换后的UI坐标。然后将坐标赋值给UI元素的localPosition
RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("CanvasScreen").GetComponent<RectTransform>(), Camera.main.WorldToScreenPoint(this.transform.position), Camera.main, out screenPoint);
GameObject go = Instantiate(Resources.Load<GameObject>("TextScreen"), GameObject.Find("CanvasScreen").transform);
go.transform.localPosition = screenPoint;