Input.GetAxis( '')Input.GetAxisRaw( '')



Input Getaxis Quot Quot



入力 .GetAxisGet軸

静的関数 GetAxis (( axisName :文字列):フロート



説明 説明

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



軸名に従って仮想座標系の値を返します。

input.GetAxis Usage(GetAxis( 'Mouse X')、GetAxis( 'Mouse Y')、GetAxis( 'Mouse ScrollWheel')、GetAxis( 'Vertical')、GetAxis( 'Horizo​​ntal')、

GetAxisは、パラメーターを渡す必要があるメソッドです。パラメータは文字列型です。パラメータは次のとおりです。



1つ:タッチスクリーンカテゴリ

1.画面に沿ってマウスXマウスバツ移動時にトリガー

2.画面に沿ったマウスYマウスY移動時にトリガー

3.マウスScrollWheelマウスの場合スクロールホイールスクロール時にトリガーされます

2:キーボード操作

を押すと、キーボードの上下の矢印に対応します上か下矢印でトリガー(w s)

を押すと、キーボードの左右の矢印に対応します左か右矢印でトリガー(a d)

ゲームの実行中に、設定したキーボードを押すか、マウスをドラッグすると、1から-1までの値が返されます。例えば: 0-0.123-0.245-0.672-0.89-1.0

値の変化は速度に関連しています、


equal, Initially confirmed that my conjecture should be correct. Then I putUpdateMethod changed toFixedUpdate, Run again, the console still always outputsequal

}

private float lastFrameMousePositonY = 0 void Update() { // The offset of the mouse in the Y direction relative to the previous frame in this frame float offset = Input.mousePosition.y - lastFrameMousePositonY if(Input.GetAxis('Mouse Y') - offset <0.0001) { print('equal') } lastFrameMousePositonY = Input.mousePosition.y }

静的関数 GetAxisRaw (( axisName :文字列):フロート

説明 説明

平滑化フィルタリングが適用されていない、axisNameで識別される仮想軸の値を返します。

座標軸名でフィルターを平滑化せずに仮想座標値を返します。

ゲームの実行中に、設定したキーボードを押すと、1と-1の2つの値が返されます


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) } 
原理:


メソッドパラメータaxisNameで指定された軸上の入力デバイスの変位を返します。今回メソッドが呼び出されたときの軸上の入力デバイスの位置によって変位が決定され、

これは、メソッドが最後に呼び出されたときの軸上の入力デバイスの位置を減算することによって取得されます。


コードを確認してください

次のコードで私の理解を確認してください。 Unityでシーンを実行した後、コンソールは常に出力

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) } }
もう一度入力しますFixedUpdateデフォルトからの1秒あたりの頻度501秒あたりの時間5タイムズ、実行中のシーンはまだ出力します等しい

using UnityEngine using System.Collections public class ExampleClass :  MonoBehaviour  { void Update() { float speed =  Input.GetAxisRaw ('Horizontal') *  Time.deltaTime  transform.Rotate(0, speed, 0) } }

出力結果:

画像