- 1、本文档共4页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Unity 油门控制器
还是一篇41post的翻译,对于老鸟们可能就没用了,这个脚本太简单了,但是小小鸟们可以看看,或许有点用能,希望大家喜欢!!!????下面正文:????这个Unity编程教程将展示如何创建一个让GameObject保持预订速率向前移动的脚本。这个油门速率控制器可以应用在像船,飞机,火车上。照例,Unity工程文件会在文章的结尾提供下载。????本教程的灵感来自于半条命,有一辆玩家可以驾驶的列车,你们可能已经不怎么记得了,来看看这张截图:下面这段代码也可以做到如此。来看看代码:usingUnityEngine;??usingSystem.Collections;??publicclassThrottleController : MonoBehaviour??{?????? //The game objects Transform????privateTransform goTransform;??????//the throttle increment to the current velocity????privatefloatincrement=0.0f;??????//this variable stores the vertical axis values????privatefloatvertAxis=0.0f;??????//the throttle????privatefloatthrottle =0.0f;??????voidAwake ()??????{??????????//get this game objects Transform????????goTransform =?this.GetComponentTransform();??????}??????voidUpdate ()??????{??????????//Get the vertical input value and store it at the vertAxis variable????????vertAxis = Input.GetAxis(Vertical);??????????//change the increment value based on the vertical input????????if(vertAxis0)??????????{??????????????increment = 0.05f;??????????}??????????else?if(vertAxis0)??????????{??????????????increment = -0.05f;??????????}??????????//after releasing the vertical axis, add the increment the throttle????????if(Input.GetButtonUp(Vertical))??????????{??????????????throttle = throttle+increment;??????????}??????????//set the throttle limit between -0.05f (reverse) and 0.25f (max speed)????????throttle=Mathf.Clamp(throttle, -0.05f,0.25f);??????????//translates the game object based on the throttle????????goTransform.Translate(throttle * Vector3.forward);??????????//rotates the game object, based on horizontal input????????goTransform.Rotate(Vector3.up * Input.GetAxis(Horizontal));??????}??}??????实质上,这个脚本是检查垂直轴的按钮是否被按下和释放。然后,将增量加上垂直输入的值加上添加的油门变量设置为使GameObject移动的速率。这是核心内容。????首先要声明goTransform为Transform变量(例如第7行),之后在代码中存储GameObject的Transform将被用到。下面,我们有3个浮点数被声明并初始化:???? increment?,改变油门的值。???? vertAxis,存储键盘输入结果,在1到-1之间???? throttle,GameObject的移动速率(例如第10,12,14行)????然后,在Awake()方法中有一行初始化goTransform的代码(例如
您可能关注的文档
最近下载
- SY_T 5660-2020 钻井液用包被絮凝剂 聚丙烯酰胺类.pdf VIP
- 2021-202x年基金管理人员工跟投基金投资协议-经典(律师审定版).docx
- 2010-2015年 中国电梯行业市场发展前景及投资分析报告.doc
- 78度智慧参考资料.pdf
- 基层儿科医务人员服务能力提升学习班答案-2024华医网继续教育答案.docx VIP
- DELTA台达伺服驱动器 ASDA-A2使用手册-操作说明书.pdf
- 国际贸易实务英文版(第五版)周瑞琪教材辅导习题解答.pdf
- 基于高斯滤波和近似积分的电动车窗防夹算法.pdf
- Application for Export Transaction 离岸客户填写指南.doc VIP
- 2023年膨化食品行业市场需求分析报告及未来五至十年行业预测报告.docx
文档评论(0)