当前位置:网站首页>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/
这位道友请留步️,我观你气度不凡,谈吐间隐隐有王者霸气,日后定有一番大作为!!!旁边有点赞收藏今日传你,点了吧,未来你成功️,我分文不取,若不成功️,也好回来找我。
温馨提示:点击下方卡片获取更多意想不到的资源。
边栏推荐
- 04个人研发的产品及推广-数据推送工具
- Vscode matches and replaces the brackets
- [reverse intermediate] eager to try
- Program counter of JVM runtime data area
- 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
- Display picture of DataGridView cell in C WinForm
- Guidelines for preparing for the 2022 soft exam information security engineer exam
- TCP连接不止用TCP协议沟通
- The art of Engineering (1): try to package things that do not need to be exposed
- [translation] principle analysis of X Window Manager (I)
猜你喜欢
学 SQL 必须了解的 10 个高级概念
BearPi-HM_ Nano development board "flower protector" case
集成开发管理平台
BearPi-HM_ Nano development environment
Huawei certified cloud computing hica
TCP connection is more than communicating with TCP protocol
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
[reverse] repair IAT and close ASLR after shelling
The NTFS format converter (convert.exe) is missing from the current system
JUnit unit test
随机推荐
Integrated development management platform
Application service configurator (regular, database backup, file backup, remote backup)
Flink parsing (III): memory management
Models used in data warehouse modeling and layered introduction
微信防撤回是怎么实现的?
【MySQL入门】第三话 · MySQL中常见的数据类型
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
灵活报表v1.0(简单版)
Kali2021 installation and basic configuration
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
connection reset by peer
Automatic operation and maintenance sharp weapon ansible Playbook
Serial serialold parnew of JVM garbage collector
Redis installation on centos7
MySQL Advanced (index, view, stored procedures, functions, Change password)
Example of batch update statement combining update and inner join in SQL Server
07个人研发的产品及推广-人力资源信息管理系统
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
EasyRE WriteUp