当前位置:网站首页>Unity学习笔记(实现传送带)
Unity学习笔记(实现传送带)
2022-07-27 16:22:00 【Miracle Fan】
Unity模拟传送带
1.模型搭建
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BkSshMPi-1648975107093)(../图片/image-20220403163130633.png)]](/img/1b/036b5b6dd1d8790b34c07323e483b3.png)
2.添加部件
2.1添加触发器
为传送带添加触发器,使得当物体停留在传送带时能一直向前移动。
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WfnbyINh-1648975107095)(../图片/image-20220403162956315.png)]](/img/4e/c196bd42d29817f42d5e033a49dea1.png)
2.2 设置空物体作为传送带终点位置
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oNIYFSmM-1648975107096)(../图片/image-20220403163425279.png)]](/img/8c/cacf0f40b7f59b8dd61ce97f538442.png)
2.3为传送带设置开关和速度加速装置
本展示的传送带开关装置是通过空格键进行控制,加速装置通过数字1控制
3. 源代码
public GameObject belt;
public Transform endpoint;//获取终点位置
public int currentSpeed;//当前速度
public int maxSpeed;//传送带最大速度
public bool belton=false;//判断传送带是否开启
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
PowerSwitch();
}
else if (Input.GetKeyDown(KeyCode.Alpha1))
{
ChangeSpeed();
}
}
void ChangeSpeed()
{
if(currentSpeed>=maxSpeed)
{
currentSpeed = 0;
}
else
{
currentSpeed++;
}
}
void PowerSwitch()
{
if(belton)
{
belton = false;
}
else
{
belton = true;
}
}
private void OnTriggerStay(Collider collider)
{
if(belton)
{
collider.transform.position = Vector3.MoveTowards(collider.transform.position, endpoint.position, currentSpeed * Time.deltaTime);
}
}
4.Demo
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jWElVL60-1648975107097)(../图片/4-16489734944431.gif)]](https://img-blog.csdnimg.cn/5d5abdd46366425d953120ebe6404ccc.gif)
边栏推荐
猜你喜欢

npm 基本使用

Examples of map search

I'm stupid. When completable future is used with openfegin, it even reports an error

瑞吉外卖笔记

TypeScript安装

CMD 命令

Sentinel1.8.4 persistent Nacos configuration

面试官:你觉得你最大的缺点是什么?

The understanding of string in C.

Here are all the MySQL interview questions you can't expect (the latest version of 2022)
随机推荐
LeetCode 刷题 第二天
Sentinel1.8.4 persistent Nacos configuration
Latex使用--subfigure竖排图形
Product recommendation and classified product recommendation
Low noise anion fan touch IC
Arrays and objects in JS
I'm stupid. When completable future is used with openfegin, it even reports an error
商品名称模糊搜索:
Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
Uploading and downloading of files
Matplotlib(基本用法)
Use mobaxtermto establish a two-tier springboard connection
pygame飞机大战游戏背景实现
Baidu map eagle eye track service
浅谈JVM(面试常考)
Wechat payment and payment callback
Typeerror: conv2d(): argument 'padding' (position 5) must be multiple of ints, not STR [error]
`this.$emit` 子组件给父组件传递多个参数
正则表达式的扩展
地图找房的实例