从世界坐标转换成ui的rect坐标的方法

这个东西整整折磨了我一个通宵。原谅我先这样放上来。明天整理整理

 

 

 1 using UnityEngine;
 2 using System.Collections;
 3 using UnityEngine.UI;
 4 
 5 public class test_temp2 : MonoBehaviour {
 6 public GameObject 要出现的世界点;
 7 public Camera 摄像机;
 8 private RectTransform 要修改的屏幕点;
 9 public GameObject 预制件;
10 private GameObject 脚跟死皮;
11 //预制件的名字是 canvas/jiafen
12 
13 
14 public void 大狗逼熬夜一晚上才整明白的傻逼方法()
15 {
16 
17 //你妈的无论是GetComponent还是GetComponentInChildren()都只能获得canvas预制件的父组件,尼玛有什么用啊 害我一晚上没睡
18 脚跟死皮 = Instantiate(预制件);
19 脚跟死皮.GetComponent<RectTransform>().FindChild("jiafen").GetComponent<RectTransform>().anchoredPosition=
20 RectTransformUtility.WorldToScreenPoint(摄像机, 要出现的世界点.transform.position);
21 //temp.GetComponentInChildren<RectTransform>().anchoredPosition= RectTransformUtility.WorldToScreenPoint(摄像机, 要出现的世界点.transform.position);
22 //temp.GetComponentInChildren<Text>().text = temp.GetComponentInChildren<RectTransform>().FindChild("jiafen").GetComponent<RectTransform>().anchoredPosition.ToString();
23 //temp.GetComponentInChildren<RectTransform>().anchoredPosition = new Vector2(320.6f, 70.1f);
24 //temp.GetComponentInChildren<RectTransform>().anchoredPosition;
25 //要修改的屏幕点 = temp.GetComponentInChildren<RectTransform>();//获得要修改坐标的物体
26 //要修改的屏幕点.anchoredPosition= RectTransformUtility.WorldToScreenPoint(摄像机, 要出现的世界点.transform.position);
27 //temp.GetComponentInChildren<Text>().text= "asdlkfjalsdkf";
28 Destroy(脚跟死皮.gameObject, 1f);
29 //草泥马终于整明白了。原来temp.GetComponentInChildren<RectTransform>()获得的还是父物体
30 
31 }
32 }

 

posted @ 2015-12-20 05:56  vsDog  阅读(1403)  评论(0编辑  收藏  举报