言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Input.GetAxis

public static function GetAxis(axisName: string): float;

Description

/axisName/ で識別される仮想軸の値を返します

値はキーボードとジョイスティックの入力によって-1から1の範囲になります。 軸がマウスの移動量で設定される場合、マウスの移動量は軸感度を乗算するので、 -1...1の範囲ではなくなります。 これは独立したフレームレートで動作しています。よって、この関数を使った値を使用するとき、フレームレートが変更された時のことを考える必要はありません。

	// 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);
	}
	// 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);
	}