当前位置:网站首页>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/
这位道友请留步️,我观你气度不凡,谈吐间隐隐有王者霸气,日后定有一番大作为!!!旁边有点赞收藏今日传你,点了吧,未来你成功️,我分文不取,若不成功️,也好回来找我。
温馨提示:点击下方卡片获取更多意想不到的资源。
边栏推荐
- C WinForm series button easy to use
- Flink parsing (III): memory management
- mysql高級(索引,視圖,存儲過程,函數,修改密碼)
- Automatic operation and maintenance sharp weapon ansible Foundation
- Distributed (consistency protocol) leader election (dotnext.net.cluster implements raft election)
- Summary of study notes for 2022 soft exam information security engineer preparation
- Grafana 9 is officially released, which is easier to use and more cool!
- PySpark算子处理空间数据全解析(4): 先说说空间运算
- 07个人研发的产品及推广-人力资源信息管理系统
- 【MySQL入门】第一话 · 初入“数据库”大陆
猜你喜欢
【ASM】字节码操作 ClassWriter 类介绍与使用
06个人研发的产品及推广-代码统计工具
C#版Selenium操作Chrome全屏模式显示(F11)
BearPi-HM_ Nano development environment
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
Flink analysis (II): analysis of backpressure mechanism
CTF逆向入门题——掷骰子
06 products and promotion developed by individuals - code statistical tools
C# NanoFramework 点灯和按键 之 ESP32
Flink parsing (IV): recovery mechanism
随机推荐
信息与网络安全期末复习(基于老师给的重点)
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
TCP连接不止用TCP协议沟通
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Interpretation of Flink source code (II): Interpretation of jobgraph source code
02 personal developed products and promotion - SMS platform
[reverse] repair IAT and close ASLR after shelling
JUnit unit test
JVM class loading subsystem
C # nanoframework lighting and key esp32
【MySQL入门】第三话 · MySQL中常见的数据类型
Binary search strategy
How to submit data through post
【MySQL入门】第一话 · 初入“数据库”大陆
Huawei certified cloud computing hica
信息与网络安全期末复习(完整版)
全网最全tcpdump和Wireshark抓包实践
Solid principle
Final review of information and network security (full version)
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias