Input.GetAxis("") Input.GetAxisRaw("")
2018-03-27 00:37
801 查看
Input.GetAxis 获取轴static function GetAxis (axisName : string) : floatDescription描述Returns the value of the virtual axis identified by axisName.根据坐标轴名称返回虚拟坐标系中的值。input.GetAxis 用法(GetAxis("Mouse X"),GetAxis("Mouse Y"),GetAxis("Mouse ScrollWheel"),GetAxis("Vertical "),GetAxis("Horizontal "), GetAxis 是个方法,需要传参数,参数为string类型,参数如下: 一:触屏类 1.Mouse X 鼠标沿着屏幕X移动时触发 2.Mouse Y 鼠标沿着屏幕Y移动时触发 3.Mouse ScrollWheel 当鼠标滚动轮滚动时触发 二:键盘操作类 1.Vertical 对应键盘上面的上下箭头,当按下上或下箭头时触发 ( w s ) 2.Horizontal 对应键盘上面的左右箭头,当按下左或右箭头时触发 (a d) 当在游戏运行的时候,按下你设置好的键盘,或拖拽鼠标就会返回 1和-1之间的值 如: 0 - 0.123 - 0.245 - 0.672 - 0.89 - 1.0
值变化和快慢有关,
using UnityEngine;
using System.Collections;
public class ExampleClass : 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);
}
}using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public float horizontalSpeed = 2.0F;
public float verticalSpeed = 2.0F;
void Update() {
float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = verticalSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(v, h, 0);
}
}
返回输入设备在方法参数axisName所指定的轴上的位移量,该位移量由此次调用该方法时输入设备在轴上的位置与上次调用该方法时输入设备在轴上的位置相减得出。
值变化和快慢有关,
using UnityEngine;
using System.Collections;
public class ExampleClass : 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);
}
}using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public float horizontalSpeed = 2.0F;
public float verticalSpeed = 2.0F;
void Update() {
float h = horizontalSpeed * Input.GetAxis("Mouse X");
float v = verticalSpeed * Input.GetAxis("Mouse Y");
transform.Rotate(v, h, 0);
}
}
Input.GetAxisRaw 获取原始轴
static function GetAxisRaw (axisName : string) : floatDescription描述Returns the value of the virtual axis identified by axisName with no smoothing filtering applied.通过坐标轴名称返回一个不使用平滑滤波器的虚拟坐标值。当在游戏运行的时候,按下你设置好的键盘就会返回 1和-1这两个值using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { float speed = Input.GetAxisRaw("Horizontal") * Time.deltaTime; transform.Rotate(0, speed, 0); } }原理:
返回输入设备在方法参数axisName所指定的轴上的位移量,该位移量由此次调用该方法时输入设备在轴上的位置与上次调用该方法时输入设备在轴上的位置相减得出。
检验代码
通过下面的代码对我的理解进行检验,在Unity中运行场景后,控制台始终输出equal,初步证实我的猜想应该是正确的。而后我把Update方法改为FixedUpdate,再次运行,控制台仍然始终输出equal再把FixedUpdate的频率从默认的每秒50次改成每秒5次,运行场景仍然输出equal。
private float lastFrameMousePositonY = 0; void Update() { // 此帧中鼠标在Y方向上相对上一帧的偏移量 float offset = Input.mousePosition.y - lastFrameMousePositonY; if(Input.GetAxis("Mouse Y") - offset < 0.0001) { print("equal"); } lastFrameMousePositonY = Input.mousePosition.y; }输出结果:
相关文章推荐
- file_get_contents("php://input", "r")
- <form action="get.php" method="post" id="tform"> <input type="text" name="one"> <a href="jav
- 我的和unity3d的小故事1——恶魔射手之鼠标控制移动之input.getaxis("Horizontal")与input.getaxis("Vertical")
- file_get_contents(&quot;php://input&quot;);
- file_get_contents("php://input")
- Jsp中request.getParameter("@param")值为[object HTMLInputElement]
- file_get_contents("php://input")的使用方法
- file_get_contents("php://input")
- 关于file_get_contents("php://input")
- document.getElementById("xx").style.xxx中的所有属性
- Form表单中method="post/get'的区别
- jQuery操作<input type="radio">
- FORM的ENCTYPE="multipart/form-data" 时request.getParameter()值为null问题的解决
- Exception in thread "main" java.util.InputMismatchException
- 警告:"System.Configuration.ConfigurationSettings.GetConfig(string)”已过时
- 报错:For input string: "filter_imports"。
- 一个字符串A的子串被定义成从A中顺次选出若干个字符构成的串。如A=“cdaad" ,顺次选1,3,5个字符就构成子串" cad" ,现给定两个字符串,求它们的最长共公子串。 Input 第一行两个字
- struts2文件下载及 <param name="inputName">inputStream</param>的理解
- 让HTML中的文本框<input type="text">中的文字垂直居中
- jquery版本升级不兼容的问题:$("input").attr("value")功能发生改变