Unity3D之float Input.GetAxis(string axisname)
2016-01-02 12:05
573 查看
本人学习Unity3D第一次发博客。
Input.GetAxis(string axisname)方法返回一个float 类型的数。范围在-1到1之间,如果获取的是鼠标的运动,则不再是-1到1之间,它会随你的鼠标速度变化。
参数内容如下:
1.触屏类:
MouseX 鼠标按着并沿着屏幕X轴方向滑动时触发
MouseY
鼠标按着并沿着屏幕Y轴方向滑动时触发
Mouse ScrollWheel 当鼠标滚动轮滚动时触发
2.键盘操作类:
1.Vertical 对应键盘上面的上下箭头,当按下上或下箭头时触发
2.Horizontal 对应键盘上面的左右箭头,当按下左或右箭头时触发
Input.GetAxis(string axisname)方法返回一个float 类型的数。范围在-1到1之间,如果获取的是鼠标的运动,则不再是-1到1之间,它会随你的鼠标速度变化。
参数内容如下:
1.触屏类:
MouseX 鼠标按着并沿着屏幕X轴方向滑动时触发
MouseY
鼠标按着并沿着屏幕Y轴方向滑动时触发
Mouse ScrollWheel 当鼠标滚动轮滚动时触发
2.键盘操作类:
1.Vertical 对应键盘上面的上下箭头,当按下上或下箭头时触发
2.Horizontal 对应键盘上面的左右箭头,当按下左或右箭头时触发
[code] using UnityEngine; using System.Collections; public class example :Monobehaviour { public float speed = 10.0F; public float rotationSpeed = 100.0F; void Update() { float translation = Input.GetAxis("Vertical") * speed; float rotation = Input.GetAxis("Horizontal") * rotationSpeed; translation *= Time.deltaTime; rotation *= Time.deltaTime; transform.Translate(0, 0, translation); transform.Rotate(0, rotation, 0); } }
[code]// A very simplistic car driving on the x-z plane. // 一个十分简单的在x-z平面的驾车例子 var speed : float = 10.0; var rotationSpeed : float = 100.0; function Update () { // Get the horizontal and vertical axis. //获取横向和纵向坐标轴 // By default they are mapped to the arrow keys. //默认情况下他们关联到方向键上 // The value is in the range -1 to 1 //值的范围是在-1到1之间 var translation : float = Input.GetAxis ("Vertical") * speed; var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed; // Make it move 10 meters per second instead of 10 meters per frame... // 使它每帧移动10米变为每秒移动10米... translation *= Time.deltaTime; rotation *= Time.deltaTime; // Move translation along the object's z-axis //沿着z轴平移对象 transform.Translate (0, 0, translation); // Rotate around our y-axis //以我们的y轴为中心旋转
相关文章推荐
- Unity5脚本事件函数及其执行顺序
- Unity3D 经常使用库
- [转]How to translate WORLD coordinates to TERRAIN coordinates in Unity3d
- Unity-Animator深入系列---StateMachineBehaviour状态机脚本学习
- Unity+NGUI性能优化方法总结
- unity 2D总结(转发 忘记源地址了)
- unity4.6_摄像机跟随模式、观察模式融合(平滑)
- Unity3D教程:动画融合、动画层、动画混合、附加动画、程序动画、动画重放和取样
- Unity3D与Android,iOS交互
- 使用VS调试Unity脚本
- Unity 官方 Demo: 2DPlatformer 的 SLua 版本。
- unity中特殊文件夹
- Unity3D研究院之两种方式播放游戏视频
- Unity3d Fast Indirect illumination Using Two Virtual Spherical Gaussian Lights-Square Enix论文 ver 2
- unity3d游戏开发之UV贴图教程
- 【学习笔记】 Unity中在点击UI时屏蔽游戏内点击事件
- Unity3D中Layers和LayerMask解析
- Unity 编辑器启动时运行自定义编辑器脚本
- unity3D Animator 播放界面动画第一帧闪烁问题
- Unity3D游戏开发之详解 Animation类和Animator类