와와

[절대강좌유니티] 14. Input System 본문

카테고리 없음

[절대강좌유니티] 14. Input System

정으주 2022. 2. 8. 20:12
 

14. Input System

1) Imput System의 구조

 Action : 게임 내의 행동, 동작 ( ex. 이동, 회전, 공격, 점프 )

 BInding : Action을 실제 물리적인 입력장치와 매핑하는 것 ( 점프 - 키보드 스페이스 키 )

 Action Map : 여러 Action의 그룹 ( ex. UI, Player )

 

 

2) Imput System 패키지 설치

 

  패키지 매니저 > Unity Registry > Input System 설치

 

3) Input Actions 에셋

 

 

4) Player Input 컴포넌트

 

   캐릭터에 컴포넌트 추가 후 Input Actions 에셋 바인딩

 

  1. Behavior - Send Messages 옵션

    : Input Actions에서 설정한 액션을 SendMessage 함수를 이용하여 호출

 

#pragma warning disable IDE0051

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerCtrl : MonoBehaviour
{

    void OnMove(InputValue value)
    {
        Vector2 dir = value.Get<Vector2>();
        Debug.Log($"Move = ({dir.x},{dir.y})");

    }

    void OnAttack()
    {
        Debug.Log("Attack");
    }
}

 

2. Behavior - Invoke Unity Events 옵션

 

 

3. Behavior - Invoke C Sharp Events 옵션