当前位置:网站首页>[unity notes] screen coordinates to ugui coordinates
[unity notes] screen coordinates to ugui coordinates
2022-07-07 02:20:00 【Start()】
API :
RectTransformUtility Static functions under class ScreenPointToLocalPointInRectangle
You need to pass in four parameters ,
① RectTransform:
This parameter is equivalent to indicating A canvas , The screen coordinate point is the position of the canvas . Under the canvas UI Coordinate changes are shown in the figure :

② Vector2
Screen coordinates , From bottom left to top right , Use " Input.mousePosition " Can be judged

③ Camera
Canvas The rendering mode is Camera Of , The camera needs to be filled in this parameter ;Overlay Can be filled directly null
④ out Vector2
Output conversion completed UGUI coordinate
The following implementation UI As the mouse moves :

Implementation code :
public RectTransform rect;// Based on which Rect Transform
public RectTransform targetRect;// Following the movement of the mouse UI
void Update()
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, Input.mousePosition, null, out Vector2 v2);
targetRect.localPosition = v2;
}
What we use here is Recttransform.localPosition instead of anchoredPosition,anchoredPosition Is based on the current UI Anchor point to get the coordinate position , If the anchor point is in the center, it is and localPosition equal , Make a note of ~
边栏推荐
- Time synchronization of livox lidar hardware -- PPS method
- 云原生混部最后一道防线:节点水位线设计
- 一片叶子两三万?植物消费爆火背后的“阳谋”
- Sensor: DS1302 clock chip and driver code
- 3D laser slam: time synchronization of livox lidar hardware
- How to use strings as speed templates- How to use String as Velocity Template?
- 猫猫回收站
- 大咖云集|NextArch基金会云开发Meetup来啦!
- A new path for enterprise mid Platform Construction -- low code platform
- Livox激光雷达硬件时间同步---PPS方法
猜你喜欢

豆瓣平均 9.x,分布式领域的 5 本神书!
![[unique] what is the [chain storage structure]?](/img/cd/be18c65b9d7faccc3c9b18e3b2ce8e.png)
[unique] what is the [chain storage structure]?

3D laser slam: time synchronization of livox lidar hardware

UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢

2022/0524/bookstrap

argo workflows源码解析

老板被隔离了

leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
![[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks](/img/06/17acf9958228cce5d80ada3275ad24.png)
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks

centos8安裝mysql報錯:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
随机推荐
ROS learning (22) TF transformation
CISP-PTE之命令注入篇
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Metaforce force meta universe development and construction - fossage 2.0 system development
NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“
Analyze "C language" [advanced] paid knowledge [i]
激光雷达:Ouster OS产品介绍及使用方法
Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
Lumion 11.0软件安装包下载及安装教程
ROS learning (26) dynamic parameter configuration
张平安:加快云上数字创新,共建产业智慧生态
如何从0到1构建32Core树莓派集群
GEE升级,可以实现一件run tasks
Analyze "C language" [advanced] paid knowledge [II]
Collection recommandée!! Quel plug - in de gestion d'état flutter est le plus fort? Regardez le classement des manons de l'île, s'il vous plaît!
Why am I warned that the 'CMAKE_ TOOLCHAIN_ FILE' variable is not used by the project?
Introduction to FLIR blackfly s industrial camera
centos8 用yum 安装MySQL 8.0.x
老板被隔离了
【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations