unity制作瞄准镜效果
作者:yaoruijie 时间:2022-04-15 23:45:10
使用unity制作瞄准镜,供大家参考,具体内容如下
一、创建场景
在Hierarchy窗口中使用Plane和Cube创建场景,并调整摄像机位置
二、使用步骤
1.在Hierarchy窗口中右击在UI中选择Image
2.将瞄准镜素材拖入Image的检视试图中Soure Image中
结果如下:
(注意在导入图片时将图片类型更改为下图所示,更改完之后点击Apply)
3.调整瞄准镜位置
三.新建代码
代码如下(示例):
using UnityEngine;
using System.Collections;
public class bj : MonoBehaviour
{
public GameObject obj;//声明一个可以外部拖拽赋值的游戏物体
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))//获取鼠标按键按下,“0”为鼠标左键
{
obj.SetActive(true);
Camera.main.fieldOfView = 20;
}
if (Input.GetMouseButtonDown(1))//获取鼠标按键按下,“1”为鼠标右键
{
obj.SetActive(false);
Camera.main.fieldOfView = 60;
}
}
}
将代码挂载在main camera上,并将Image拖拽到代码中的obj上
接下来就可以运行啦!
来源:https://blog.csdn.net/yaoruijie/article/details/116033607
标签:unity,瞄准镜
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaWeb项目部署到服务器详细步骤详解
2023-11-29 11:15:20
![](https://img.aspxhome.com/file/2023/4/58764_0s.png)
C#实现GZip压缩和解压缩入门实例
2021-05-29 08:20:45
java实现面板之间切换功能
2021-12-03 15:06:39
![](https://img.aspxhome.com/file/2023/5/72655_0s.jpg)
Springboot Thymeleaf模板文件调用Java类静态方法
2023-11-25 05:34:47
Java对象在JVM中的生命周期详解
2023-11-24 16:15:03
![](https://img.aspxhome.com/file/2023/1/59961_0s.png)
java实现Yaml转Json示例详解
2023-12-06 22:58:34
SpringBoot中@Import注解如何正确使用
2023-07-28 12:36:16
![](https://img.aspxhome.com/file/2023/7/57707_0s.png)
springboot远程debug调试全过程
2023-11-25 07:05:56
![](https://img.aspxhome.com/file/2023/7/60247_0s.png)
c语言动态数组示例
2023-11-02 22:56:44
详解用Spring Boot Admin来监控我们的微服务
2022-02-12 15:18:03
Java如何解决发送Post请求报Stream closed问题
2021-12-12 04:20:10
![](https://img.aspxhome.com/file/2023/6/64956_0s.jpg)
eclipse中自动生成javadoc文档的方法
2022-04-08 17:54:12
详解基于MVC的数据查询模块进行模糊查询
2022-02-13 19:26:49
Unity实现攻击范围检测并绘制检测区域
2023-09-18 21:59:10
![](https://img.aspxhome.com/file/2023/7/67557_0s.jpg)
Springbean的几种注入方式都了解吗
2023-01-09 05:37:10
Java排序的那些事之sort方法的使用详解
2023-01-22 00:18:35
![](https://img.aspxhome.com/file/2023/4/61014_0s.png)
java实现ftp上传 如何创建文件夹
2021-06-10 10:49:17
java 命名空间 命名规则第1/2页
2021-06-06 14:20:19
Java如何解析html中的内容并存到数据库详解
2023-11-29 05:08:32
全面解析SpringBoot文件上传功能
2023-02-26 15:55:56
![](https://img.aspxhome.com/file/2023/2/67462_0s.png)