티스토리 뷰

728x170

Old Input system

아래는 예전 방식의 Input 처리 코드로, 기본적으로 프로젝트는 이 방식을 사용하지 않는다.

아래와 같이 Active Input Handling을 변경하면 이 코드가 동작한다. 

  • Unity 2019 이상에서는 Input System을 새로 설치하면 기존 Input API (Input.GetKey)가 비활성화됩니다.
  • 해결 방법:
    • 메뉴: Edit > Project Settings > Player > Other Settings
    • Active Input Handling이 Both 또는 Input Manager로 설정되어 있는지 확인
using UnityEngine;

public class Player : MonoBehaviour
{
    public float speed = 5f;

    void Update()
    {
        if (Input.GetKey(KeyCode.W))
        {
            transform.position += Vector3.up * speed * Time.deltaTime;
        }
    }
}

 

New Input System

기본적으로 New Input System을 사용하도록 프로젝트가 만들어진다.

프로젝트 설정을 변경하지 않아도, 아래 코드는 동작한다. 

using UnityEngine;

using UnityEngine.InputSystem;

public class Player : MonoBehaviour
{
    void Start()
    {
        
    }

    void Update()
    {
        if (Keyboard.current.wKey.isPressed)
        {
            transform.position = transform.position + new Vector3(0, 1, 0);
        }
    }
}
그리드형
공지사항
최근에 올라온 글
최근에 달린 댓글
링크
«   2025/10   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함
세로형