当前位置:网站首页>Unity learning notes (realize the conveyor belt)
Unity learning notes (realize the conveyor belt)
2022-07-27 19:04:00 【Miracle Fan】
List of articles
Unity Analog conveyor belt
1. Model structures,
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-BkSshMPi-1648975107093)(../ picture /image-20220403163130633.png)]](/img/1b/036b5b6dd1d8790b34c07323e483b3.png)
2. Add part
2.1 Add trigger
Add a trigger to the conveyor , So that when the object stays on the conveyor belt, it can move forward .
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-WfnbyINh-1648975107095)(../ picture /image-20220403162956315.png)]](/img/4e/c196bd42d29817f42d5e033a49dea1.png)
2.2 Set the empty object as the end position of the conveyor belt
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-oNIYFSmM-1648975107096)(../ picture /image-20220403163425279.png)]](/img/8c/cacf0f40b7f59b8dd61ce97f538442.png)
2.3 Set the switch and speed acceleration device for the conveyor belt
The conveyor belt switching device shown in this display is controlled by the space bar , The acceleration device passes through the digital 1 control
3. Source code
public GameObject belt;
public Transform endpoint;// Get the end position
public int currentSpeed;// Current speed
public int maxSpeed;// Maximum belt speed
public bool belton=false;// Determine whether the conveyor belt is open
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
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-jWElVL60-1648975107097)(../ picture /4-16489734944431.gif)]](https://img-blog.csdnimg.cn/5d5abdd46366425d953120ebe6404ccc.gif)
边栏推荐
- WinForm screenshot save C code
- Selenium automated test interview questions family bucket
- Leetcode brushes questions the next day
- IDEA连接数据库时区问题,报红Server returns invalid timezone. Need to set ‘serverTimezone‘ property.
- Latex使用--subfigure竖排图形
- PHP字符串操作
- Product name fuzzy search:
- During the interface test, connect to the database and back up, restore and verify the data source
- Unity学习笔记——物体移动六种常见函数
- ES6数值的扩展
猜你喜欢

MySQL 02 initial experience

Kinect for Unity3D——BackgroundRemovalDemo学习

Nodejs 模板引擎ejs

Redis annotation

JMeter interface automation - how to solve the content type conflict of request headers

自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据

Day 3 of leetcode question brushing

连续时间系统的性能分析(2)-二阶系统性能改善方式PID,PR

express

MySQL 02 初体验
随机推荐
express
Interviewer: what do you think is your biggest weakness?
自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据
进行接口测试时,连接数据库,对数据源进行备份、还原、验证操作
Kinect for Unity3d----KinectManager
MySQL 02 initial experience
MongoDB
Unity学习笔记(实现传送带)
Was not registered for synchronization because synchronization is not active[resolved]
功率单位(power control)
The great idea of NS2
v-if,v-else,v-for
express
商品推荐和分类商品推荐
WPS turns off annoying advertisements
Hash、Set、List、Zset、BitMap、Scan
JDBC MySQL 02 data access and Dao mode
Useful resources for ns2
模仿线程扣除
Wechat payment and payment callback