U3D的控制
做游戏少不了控制,但是一个成熟的游戏引擎,是不能简单仅仅获取键盘中或者遥感确定的按键来控制,要考虑到用户更改游戏按键的情况,当然也得考虑到不同设备的不通输入方式,比如U3D是可以运行在iphone上的,iphone可没有键盘和上下左右键,他有平衡控制(简单化解为水平和垂直两个方向度数),如果用户使用飞行或者汽车方向盘手柄,那就不能简单用一个按键来描述了,需要有一个度数的问题(也可以简单分解为水平和垂直两个方向度数)。
U3D提供了一个Input类封装控制输入,不做详细解释,在后面我会举一些常用的例子来说明。
Class Variables
mousePositionThe current mouse position in pixel coordinates. (Read Only)
anyKeyIs any key or mouse button currently held down? (Read Only)
anyKeyDownReturns true the first frame the user hits any key or mouse button (Read Only).
inputStringReturns the keyboard input entered this frame (Read Only).
Class Functions
GetAxisReturns the value of the virtual axis identified by axisName.
GetAxisRawReturns the value of the virtual axis identified by axisName with no smoothing filtering applied.
GetButtonReturns true while the virtual button identified by buttonName is held down.
GetButtonDownReturns true during the frame the user pressed down the virtual button identified by buttonName.
GetButtonUpReturns true the first frame the user releases the virtual button identified by buttonName.
GetKeyReturns true while the user holds down the key identified by name. Think auto fire.
GetKeyDownReturns true during the frame the user starts pressing down the key identified by name.
GetKeyUpReturns true during the frame the user releases the key identified by name.
GetMouseButtonReturns whether the the given mouse button is held down.
GetMouseButtonDownReturns true during the frame the user pressed the given mouse button.
GetMouseButtonUpReturns true during the frame the user releases the given mouse button.
ResetInputAxesResets all input. After ResetInputAxes all axes return to 0 and all buttons return to 0 for one frame.
---------------------------------------------------------------------------------------------------------------------------------
获取键盘某一(这里是空格键)按键状态(bool):Input.GetKeyDown(KeyCode.Space) 这是最不通用的写法,不推荐
获取虚拟按键(这里是Jump)按键状态(bool):Input.GetButton("Jump") 推荐用这种写法,用户可以设置按键Jump为空格键(默认就是空格)
获取遥感(或iphone感应)垂直轴力度(是一个0-1之间的float):Input.GetAxis("Vertical“) 推荐写法,键盘的话默认按w或者up会瞬间提到1,要是遥感的话可以控制一个度,再乘以力的方向向量的话,就可以控制汽车之类的加速了。如果你直接写成键盘的w或者d,那就没办法控制力度了。
获取遥感(或iphone感应)水平轴力度(同上):Input.GetAxis("Horizontal")
获取鼠标中键状态:Input.GetAxis("Mouse ScrollWheel")
注:有些遥感可能水平方向会转超过1或者小于0的值出来(例如汽车遥感),为了避免错误的计算(乘以负数的话向量的方向可是会相反的),可以配合数学函数Mathf.Clamp01()来固定他的值在0和1之间。例如:
motor = Mathf.Clamp01(Input.GetAxis("Vertical")); //设置汽车引擎力度为垂直方向力度
U3D的控制的更多相关文章
- u3d人物控制
//https://blog.csdn.net/Htlas/article/details/79188008 //人物移动 http://gad.qq.com/article/detail/28921 ...
- U3D 摄像机镜头控制
如果要实现,摄像机跟随着主角运动,还有运用滚轮实现镜头的方法和缩小的实现原理 方法1:把主摄像机放到主角的下面,作为一个子对象,调整好摄像机的视角,此时就会跟随了. 方法2:用代码让摄像机的相关的po ...
- [U3D 画起重机,绑脚本和控制它运动的基本操作]
之前在学习Unity3D,不知为何网上的教学资源真是少啊...我某段时间还卡在不知如何让物体绑个脚本自动运动.. 之所以要学习U3D是因为导师让我做的IOS项目里有个需要模拟起重机,从而控制真实起重机 ...
- U3D学习09-物体简单控制及视角观察
一.Character Control非刚体 1.场景初始化,注意调整CC的轴心,不需要碰撞,且删除CC子物体的碰撞.2.移动: 获取X,Z轴变化,定义变量h,v: 定义移动 ...
- U3D DrawCall优化手记
在最近,使用U3D开发的游戏核心部分功能即将完成,中间由于各种历史原因,导致项目存在比较大的问题,这些问题在最后,恐怕只能通过一次彻底的重构来解决 现在的游戏跑起来会有接近130-170个左右的Dra ...
- [U3D 导出Xcode工程包,用Xcode给U3D脚本传递参数]
1.导出Xcode工程 File->Building and setting,导出IOS工程(有错误会失败) 2.运行Xcode工程,在Classes文件夹的UI文件夹里,早到UnityAppC ...
- 全景视频外包团队:U3D全景漫游(二)
单击Ambient Light,如下 调整为 即可设置完成 14.设置第一人称浏览 删除场景中Main Camera 将Project区域的Standard Assets下的Prefabs下的Firs ...
- Unity3D中的第三人称镜头的脚本控制
原地址:http://blog.csdn.net/mobanchengshuang/article/details/27591271 好久没有敲Blog了,谢谢大家的留言.关注.私信等支持,但是我好像 ...
- U3D 2D游戏之黑暗纪元 2D游戏基础入门开发全(1)
第一个U3D 2D游戏的例子,全部自己编写,算是入门用,这里记录一下. 1.首先游戏把层次布置好,这里分为 背景层,游戏层,UI层 背景层 (Background-1):就是单纯的背景显示作用. 游戏 ...
随机推荐
- QT:KeepAliveOption的应用
由于用QTcpSocket写网络通讯程序,当正常服务端或者客户端断开的时候,我们监测信号即可:Signals:stateChanged(QAbstractSocket::SocketState).(手 ...
- Fedora归档管理器支持Rar、7Z
最新文章:Virson's Blog 方法: 在Fedora下如何安装 RAR 压缩/解压缩程序 (RAR)? RAR格式压缩包解压 命令:yum install unrar 7z格式压缩包解压 yu ...
- php时间段判断
<?php function times(){ ini_set('date.timezone','Asia/Shanghai'); $time = date("Y-m-d H:i&qu ...
- (笔记)linux设备驱动--LED驱动
linux设备驱动--LED驱动 最近正在学习设备驱动开发,因此打算写一个系列博客,即是对自己学习的一个总结,也是对自己的一个督促,有不对,不足,需要改正的地方还望大家指出,而且希望结识志同道合的朋友 ...
- [转]Android--多线程之Handler
原文:http://www.cnblogs.com/plokmju/p/android_Handler.html 前言 Android的消息传递机制是另外一种形式的“事件处理”,这种机制主要是为了解决 ...
- e614. Setting the Initial Focused Component in a Window
There is no straightforward way to set the initial focused component in a window. The typical method ...
- (转)Ubuntu12.04上NFS Server安装使用过程
原文链接:Ubuntu12.04上NFS Server安装使用过程 实现步骤: 1.服务器端:sudo apt-get install portmap2.服务器端:sudo apt-get insta ...
- 设置 sqlserver Profiler 只监控 EF的sql执行请求
当我们用EF执行语句的时候,可以使用 sqlserver Profiler来监控到底执行了哪些sql语句,但是默认他是监控全局的,我们只想监控Ef的语句,这里如下设置 这样就只会监控 EF产生的 sq ...
- ant学习笔记-taskdef
1.声明task jar包中指定的task <taskdef name="xmltask“ classname="com.oopsconsultancy.xmltask.an ...
- 使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录
ssh-keygen 产生公钥与私钥对. ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./ss ...