从世界坐标转换成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 }

 

转载于:https://www.cnblogs.com/vsdog/p/5060212.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值