当前位置:网站首页>Unity小技巧 - 绘制瞄准准心
Unity小技巧 - 绘制瞄准准心
2022-07-06 09:38:00 【芝麻粒儿】
本文约2千字,新手阅读需要4分钟,复习需要1分钟 【收藏随时查阅不再迷路】
关于作者
众所周知,人生是一个漫长的流程,不断克服困难,不断反思前进的过程。在这个过程中会产生很多对于人生的质疑和思考,于是我决定将自己的思考,经验和故事全部分享出来,以此寻找共鸣 !!!
专注于Android/Unity和各种游戏开发技巧,以及各种资源分享(网站、工具、素材、源码、游戏等)
有什么需要欢迎私我,交流群让学习不再孤单。

实践过程
预览效果

其实实现起来非常简单,只需要Rect类和DrawTexture方法即可。
我们看看Rect里面的参数说明,
Rect(float x, float y, float width, float height)
参数一:矩形的左上角位置的x点
参数二:矩形的左上角位置的y点
参数三:矩形的右上角位置的x点
参数四:矩形的右上角位置的y点
这就是一个矩形
我们在看看DrawTexture方法,传递两个参数,参数一是矩形,参数二是目标绘制的纹理。
public class Test : MonoBehaviour
{
public Texture texture;
void OnGUI()
{
// >>1和 /2 是一样的
//绘制准心-这是根据纹理的大小来设置的矩阵大小
// Rect rect = new Rect(Input.mousePosition.x - (texture.width >> 1),
// Screen.height - Input.mousePosition.y - (texture.height >> 1), texture.width, texture.height);
// GUI.DrawTexture(rect, texture);
//这是指定矩阵大小,不管多大的纹理,都会缩放进去
int widthAndHeight = 10;
Rect rect = new Rect(Input.mousePosition.x - widthAndHeight / 2, Screen.height - Input.mousePosition.y - widthAndHeight / 2, widthAndHeight, widthAndHeight);
GUI.DrawTexture(rect, texture);
}
}
其他
作者:小空和小芝中的小空
转载说明-务必注明来源:https://zhima.blog.csdn.net/
这位道友请留步️,我观你气度不凡,谈吐间隐隐有王者霸气,日后定有一番大作为!!!旁边有点赞收藏今日传你,点了吧,未来你成功️,我分文不取,若不成功️,也好回来找我。
温馨提示:点击下方卡片获取更多意想不到的资源。
边栏推荐
- 应用服务配置器(定时,数据库备份,文件备份,异地备份)
- Solr appears write Lock, solrexception: could not get leader props in the log
- Wu Jun's trilogy insight (V) refusing fake workers
- 轻量级计划服务工具研发与实践
- Case: check the empty field [annotation + reflection + custom exception]
- [VNCTF 2022]ezmath wp
- Flink parsing (VII): time window
- Virtual machine startup prompt probing EDD (edd=off to disable) error
- Uipath browser performs actions in the new tab
- 07 personal R & D products and promotion - human resources information management system
猜你喜欢

06 products and promotion developed by individuals - code statistical tools
![[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias](/img/03/ece7f7b28cd9caea4240635548c77f.jpg)
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias

JVM 垃圾回收器之Garbage First

全网最全tcpdump和Wireshark抓包实践

Selenium test of automatic answer runs directly in the browser, just like real users.

Grafana 9 正式发布,更易用,更酷炫了!
![[rapid environment construction] openharmony 10 minute tutorial (cub pie)](/img/b5/feb9c56a65c3b07403710e23078a6f.jpg)
[rapid environment construction] openharmony 10 minute tutorial (cub pie)

虚拟机启动提示Probing EDD (edd=off to disable)错误

PyTorch 提取中间层特征?

Final review of information and network security (full version)
随机推荐
集成开发管理平台
Flink parsing (IV): recovery mechanism
Deploy flask project based on LNMP
Serial serialold parnew of JVM garbage collector
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
[ASM] introduction and use of bytecode operation classwriter class
Wu Jun's trilogy insight (V) refusing fake workers
How to submit data through post
[reverse primary] Unique
Flink analysis (II): analysis of backpressure mechanism
Connect to LAN MySQL
Redis quick start
C#WinForm中的dataGridView滚动条定位
[reverse] repair IAT and close ASLR after shelling
信息与网络安全期末复习(完整版)
Akamai anti confusion
JVM 垃圾回收器之Garbage First
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
Integrated development management platform
EasyRE WriteUp