当前位置:网站首页>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/
这位道友请留步️,我观你气度不凡,谈吐间隐隐有王者霸气,日后定有一番大作为!!!旁边有点赞收藏今日传你,点了吧,未来你成功️,我分文不取,若不成功️,也好回来找我。
温馨提示:点击下方卡片获取更多意想不到的资源。
边栏推荐
- 06个人研发的产品及推广-代码统计工具
- Redis quick start
- 分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
- Final review of information and network security (based on the key points given by the teacher)
- Interpretation of Flink source code (II): Interpretation of jobgraph source code
- The most complete tcpdump and Wireshark packet capturing practice in the whole network
- [reverse] repair IAT and close ASLR after shelling
- The problem of "syntax error" when uipath executes insert statement is solved
- Huawei certified cloud computing hica
- Selenium test of automatic answer runs directly in the browser, just like real users.
猜你喜欢
虚拟机启动提示Probing EDD (edd=off to disable)错误
Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
Flink analysis (II): analysis of backpressure mechanism
Wu Jun's trilogy experience (VII) the essence of Commerce
02 personal developed products and promotion - SMS platform
Display picture of DataGridView cell in C WinForm
Flink parsing (III): memory management
C# NanoFramework 点灯和按键 之 ESP32
03个人研发的产品及推广-计划服务配置器V3.0
随机推荐
Vscode matches and replaces the brackets
Jetpack compose 1.1 release, based on kotlin's Android UI Toolkit
遠程代碼執行滲透測試——B模塊測試
[ciscn 2021 South China]rsa writeup
[VNCTF 2022]ezmath wp
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
About selenium starting Chrome browser flash back
Quick start of Hongmeng system
Binary search strategy
Application service configurator (regular, database backup, file backup, remote backup)
轻量级计划服务工具研发与实践
Deploy flask project based on LNMP
Automatic operation and maintenance sharp weapon ansible Foundation
集成开发管理平台
信息与网络安全期末复习(基于老师给的重点)
02 personal developed products and promotion - SMS platform
Akamai talking about risk control principles and Solutions
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
Wu Jun's trilogy insight (V) refusing fake workers
【MySQL入门】第三话 · MySQL中常见的数据类型