Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

Input.GetAxis

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function GetAxis(axisName: string): float;
public static float GetAxis(string axisName);

Parámetros

Descripción

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.

This is frame-rate independent; you do not need to be concerned about varying frame-rates when using this value.

	// A very simplistic car driving on the x-z plane.

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 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... translation *= Time.deltaTime; rotation *= Time.deltaTime; // Move translation along the object's z-axis transform.Translate (0, 0, translation); // Rotate around our y-axis transform.Rotate (0, rotation, 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); } }
	// 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 var h : float = horizontalSpeed * Input.GetAxis ("Mouse X"); var v : float = verticalSpeed * Input.GetAxis ("Mouse Y"); transform.Rotate (v, h, 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); } }