2016-01-02 12:05:57 cui240558023 阅读数 1426

本人学习Unity3D第一次发博客。

Input.GetAxis(string axisname)方法返回一个float 类型的数。范围在-1到1之间,如果获取的是鼠标的运动,则不再是-1到1之间,它会随你的鼠标速度变化。

参数内容如下:

1.触屏类:

MouseX                      鼠标按着并沿着屏幕X轴方向滑动时触发

MouseY       鼠标按着并沿着屏幕Y轴方向滑动时触发

Mouse ScrollWheel      当鼠标滚动轮滚动时触发

2.键盘操作类:


                   1.Vertical                        对应键盘上面的上下箭头,当按下上或下箭头时触发
                   2.Horizontal                    对应键盘上面的左右箭头,当按下左或右箭头时触发


	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);
		}
	}
// 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轴为中心旋转

2017-07-12 14:40:10 qq_30886061 阅读数 800
 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                        对应键盘上面的上下箭头,当按下上或下箭头时触发
                   2.Horizontal                    对应键盘上面的左右箭头,当按下左或右箭头时触发
 

举个例子:物体移动(类似汽车移动)涉及知识点:Vertical 和Horizontal

代码为


2018-07-29 19:49:46 qq_38004206 阅读数 271

Input.GetAxis(string axisname)方法返回一个float 类型的数。范围在-1到1之间,如果获取的是鼠标的运动,则不再是-1到1之间,它会随你的鼠标速度变化。

1.触屏类:

                    1. MouseX                      鼠标按着并沿着屏幕X轴方向滑动时触发

                    2. MouseY       鼠标按着并沿着屏幕Y轴方向滑动时触发

                    3. Mouse ScrollWheel      当鼠标滚动轮滚动时触发

2.键盘操作类:
                   1. Vertical                        对应键盘上面的上下箭头,当按下上或下箭头时触发
                   2. Horizontal                    对应键盘上面的左右箭头,当按下左或右箭头时触发

 

 

 

 


 

 

public class example :Monobehaviour

{

    public float speed = 10.0F;

    public float rotationSpeed = 100.0F;

    void Update()

   {

                       //如果按下了上下箭头或者按下了W S键,则沿着z轴前后移动

       float translation = Input.GetAxis("Vertical") * speed;

                      //如果按下了左右箭头或者按下了A D键,则沿着旋转

       float rotation = Input.GetAxis("Horizontal") * rotationSpeed;

       translation *= Time.deltaTime;

       rotation *= Time.deltaTime;

                      //沿着z轴移动

       transform.Translate(0, 0, translation);

                      //旋转------

       transform.Rotate(0, rotation, 0);

    }

}


 
2014-03-24 14:05:56 a1294246096 阅读数 1716

Input.GetAxis 获取轴

static function GetAxis (axisName : string) : float

Description描述

Returns the value of the virtual axis identified by axisName.

根据坐标轴名称返回虚拟坐标系中的值。

The value will be in the range -1...1 for keyboard and joystick input. If the axis is setup to be delta mouse movement, the mouse delta is multiplied by the axis sensitivity and the range is not -1...1.

使用控制器和键盘输入时此值范围在-1到1之间。如果坐标轴设置为鼠标运动增量,鼠标增量乘以坐标轴灵敏度的范围将不是-1到1 。

// 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轴为中心旋转
	transform.Rotate (0, rotation, 0);
}
// Performs a mouse look.
//执行一个鼠标观察
var horizontalSpeed : float = 2.0;
var verticalSpeed : float = 2.0;
function Update () {
	// Get the mouse delta. This is not in the range -1...1
	//获取鼠标增量,范围不在-1...1
	var h : float = horizontalSpeed * Input.GetAxis ("Mouse X");
	var v : float = verticalSpeed * Input.GetAxis ("Mouse Y");
	transform.Rotate (v, h, 0);
}

Unity3D input.GetAxis

阅读数 11

没有更多推荐了,返回首页