• 从世界坐标转换成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 }
  • 相关阅读:
    安装MySQLdb
    树莓派及其他硬件平台国内外Linux镜像站全汇总
    rpc使用举例
    SAE上安装第三方模块
    【Java】Map
    【Java】判断字符串是否含字母
    【Android Studio】提示代码忽略大小写
    【iOS】Xcode 离线文档
    【iOS】iOS main() 简介
    【eclipse】No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A
  • 原文地址:https://www.cnblogs.com/vsdog/p/5060212.html
Copyright © 2020-2023  润新知