zoukankan      html  css  js  c++  java
  • 从世界坐标转换成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 }
  • 相关阅读:
    FreeMarker中List排序
    Mingyang.net:为什么不将Bean定义在Action参数中?
    长春市学校标识码
    java解析html的table
    java发送http的get、post请求【备忘】
    CentOS安装CAS 5.3.4服务端
    设置JAVA环境变量
    CentOS安装Maven
    为tomcat8安装Native library
    openresty用naxsi防xss、SQL注入
  • 原文地址:https://www.cnblogs.com/vsdog/p/5060212.html
Copyright © 2011-2022 走看看