본문 바로가기
{Programing}/Game Engine

unity - key input 관련 내용

by 탱타로케이 2021. 5. 12.

docs.unity3d.com/ScriptReference/Input.html

 

Unity - Scripting API: Input

Use this class to read the axes set up in the Conventional Game Input, and to access multi-touch/accelerometer data on mobile devices. To read an axis use Input.GetAxis with one of the following default axes: "Horizontal" and "Vertical" are mapped to joyst

docs.unity3d.com

 

키 입력

 

getkey~~ : 인수로 keycode 를 전달. 여기에 자세한 keycode 가 나열되어있다.

 

Unity - Scripting API: KeyCode

For joystick and gamepad button presses, consider using Input.GetButtonDown and Input.GetButtonUp instead of the KeyCode. These methods allow you check input state using a descriptive action string, e.g. "fire" or "jump", instead of the hardwre button numb

docs.unity3d.com

key code 는 키보드 전체는 물론, 마우스, 연결된 조이스틱 8개까지 커버 된다. 마우스는 7개 버튼, 조이스틱 하나당 버튼 20개까지 지원된다.

//누르고 있을때
if (Input.GetKey("up"))
{
	print("up arrow key is held down");
}

//눌렀을때
if (Input.GetKeyDown("space"))
{
	print("space key was pressed");
}

//뗏을 때.
if (Input.GetKeyUp("space"))
{
	print("Space key was released");
}

 

 

getbutton~~, getAxis~~ : 에디터의 Input Manager 상에서 설정한 키 이름과 키 조합을 이용.

아래 이미지처럼 키 이름에 원하는 key code를 입력하면 된다.

getAxis~~ 의 경우, Horizontal, Vertical, Mouse X,Y 같이 축을 나타내는 키만 적용할수 있다.

키별 세세한 설정치는 에디터와 여기 를 확인하자.

getMouseButton : 번호로 마우스 버튼 구분. 0,1,2 를 가지며 순서대로 왼쪽, 오른쪽, 휠버튼 으로 할당되어있다.

 

getTouch : 터치스크린이 작동한다면 구동되는 함수. 터치한 위치의 좌표와, 터치된 수를 얻을수 있다. 터치된 수는 동시에 터치된 멀티터치일때 작동.

 

https://docs.unity3d.com/Manual/class-InputManager.html

 

Unity - Manual: Input Manager

Input Manager The Input Manager window allows you to define input axes and their associated actions for your Project. To access it, from Unity’s main menu, go to Edit > Project Settings, then select Input Manager from teh navigation on the right. The Inp

docs.unity3d.com

 

'{Programing} > Game Engine' 카테고리의 다른 글

unity - lighting  (0) 2023.03.06
unity - transform  (0) 2021.05.17
Unity - 모바일 해상도 고정 대응.  (0) 2020.06.12
Unity - Particle  (0) 2020.06.12
Unity - GameObject Find  (0) 2020.06.09

댓글