Warning: Declaration of action_plugin_linebreak::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /home/stepism/www/ue4/wiki/lib/plugins/linebreak/action.php on line 41

Warning: Declaration of action_plugin_markdownextra::register(&$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /home/stepism/www/ue4/wiki/lib/plugins/markdownextra/action.php on line 16

Warning: Declaration of action_plugin_syntaxhighlighter3_action::register(Doku_Event_Handler &$controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/action/action.php on line 28
015 ユーザー入力を受け取る [stepism@UE4メモ]

ユーザ用ツール

サイト用ツール


wiki:unity:tips:015

以前のリビジョンの文書です —-


Warning: Declaration of syntax_plugin_linebreak::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /home/stepism/www/ue4/wiki/lib/plugins/linebreak/syntax.php on line 52

Warning: Declaration of syntax_plugin_linebreak::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /home/stepism/www/ue4/wiki/lib/plugins/linebreak/syntax.php on line 74

Warning: Declaration of syntax_plugin_markdownextra::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /home/stepism/www/ue4/wiki/lib/plugins/markdownextra/syntax.php on line 38

Warning: Declaration of syntax_plugin_markdownextra::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /home/stepism/www/ue4/wiki/lib/plugins/markdownextra/syntax.php on line 47

Warning: Declaration of syntax_plugin_syntaxhighlighter3_syntax::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/syntax/syntax.php on line 53

Warning: Declaration of syntax_plugin_syntaxhighlighter3_syntax::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/syntax/syntax.php on line 82

015 ユーザー入力を受け取る

概要

Inputクラスを使って、ユーザーの入力情報を受け取ります。

キーが押されたか?

if (Input.GetKeyDown("a")) 
{ 
	Debug.Log("a!"); 
} 
if (Input.GetButtonDown("Jump")) 
{ 
	Debug.Log("Jump!"); 
} 
if (Input.GetKeyDown("up")) 
{ 
	Debug.Log("up!"); 
} 

キーが押されたか?

if (Input.GetKeyUp("b")) 
{ 
	Debug.Log("b!"); 
} 
if (Input.GetButtonUp("Fire1")) 
{ 
	Debug.Log("Fire1!"); 
} 

キーを押し続けているか?

if (Input.GetKey("c")) 
{ 
	Debug.Log("c!"); 
} 
if (Input.GetButton("Fire2")) 
{ 
	Debug.Log("Fire2!"); 
} 

水平方向の入力量(-1.0fから1.0f)

float horizontal = Input.GetAxis("Horizontal"); 

垂直方向の入力量(-1.0fから1.0f)

float vertical = Input.GetAxis("Vertical");  

マウス入力

if (Input.GetMouseButtonDown(0)) 
{ 
	Debug.Log("Left Click!");	// 左クリック。 
} 
if (Input.GetMouseButtonDown(1)) 
{ 
	Debug.Log("Right Click!");	// 右クリック。 
} 
if (Input.GetMouseButtonDown(2)) 
{ 
	Debug.Log("Center Click!");	// 中央クリック。 
} 

GetMouseButtonDown( 0 ) はシングルタッチと同等です。

マウスの座標を取得

Vector2 mousePos = Input.mousePosition; 

マウスホイールの移動量を取得

float wheel = Input.GetAxis("Mouse ScrollWheel"); 

タッチ入力

for( int i = 0; i < Input.touchCount; i++ ) 
{ 
	Touch touch = Input.GetTouch(i); 
	Vector2 pos = touch.position; 
 
	switch( touch.phase ) 
	{ 
	case Began: 
		print( "touch Began!" );		// タッチ開始。 
		break; 
 
	case Moved: 
		print( "touch Moved!" );		// タッチしていて移動中。 
		break; 
 
	case Stationary: 
		print( "touch Stationary!" );	// タッチしているが移動していない。 
		break; 
 
	case Ended: 
		print( "touch Ended!" );		// タッチ終了(離した)。 
		break; 
 
	case Canceled:					// システムによってキャンセルした。 
		print( "touch Canceled!" ); 
		break; 
	}; 
} 

加速度センサーの値

Vector3 lowPassValue = Input.acceleration; 

ジャイロセンサー有効

Input.gyro.enabled = true; 

キーバインドの確認

Jumpなどキーの割り当てはEdit → Project Settings → Input で確認できます。

Unity - Input

wiki/unity/tips/015.1415935522.txt.gz · 最終更新: 2015/01/06 14:13 (外部編集)