当前位置:网站首页>[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 ~
边栏推荐
- Processing image files uploaded by streamlit Library
- 一片叶子两三万?植物消费爆火背后的“阳谋”
- 【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
- Flir Blackfly S USB3 工业相机:计数器和定时器的使用方法
- 低代码平台中的数据连接方式(上)
- [paper reading | deep reading] dngr:deep neural networks for learning graph representations
- Alibaba cloud middleware open source past
- 6 seconds to understand the book to the Kindle
- 纽约大学 CITIES 研究中心招聘理学硕士和博士后
- The last line of defense of cloud primary mixing department: node waterline design
猜你喜欢

Twenty or thirty thousand a leaf? "Yang Mou" behind the explosion of plant consumption
![[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity](/img/21/59c4d61b22e7d021b7a72a64a16b48.png)
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity

New generation cloud native message queue (I)

STM32F4---通用定时器更新中断

机器人队伍学习方法,实现8.8倍的人力回报

本周 火火火火 的开源项目!

3D激光SLAM:Livox激光雷达硬件时间同步

解密函数计算异步任务能力之「任务的状态及生命周期管理」

Centos8 install MySQL 8.0 using yum x

一片叶子两三万?植物消费爆火背后的“阳谋”
随机推荐
RC振荡器和晶体振荡器简介
投资的再思考
Redis configuration class redisconfig
STM32F4---通用定时器更新中断
3D laser slam: time synchronization of livox lidar hardware
Flir Blackfly S USB3 工业相机:计数器和定时器的使用方法
Infrared camera: juge infrared mag32 product introduction
The empirical asset pricing package (EAP) can be installed through pypi
Alibaba cloud middleware open source past
机器人队伍学习方法,实现8.8倍的人力回报
Why am I warned that the 'CMAKE_ TOOLCHAIN_ FILE' variable is not used by the project?
红外相机:巨哥红外MAG32产品介绍
sql中批量删除数据---实体中的集合
3D激光SLAM:Livox激光雷达硬件时间同步
Lidar: introduction and usage of ouster OS
Treadpoolconfig thread pool configuration in real projects
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码
建議收藏!!Flutter狀態管理插件哪家强?請看島上碼農的排行榜!
Cat recycling bin