Unity New InputSystem 键盘按键配置

Описание к видео Unity New InputSystem 键盘按键配置

using UnityEngine;
using UnityEngine.InputSystem;

public class Debug_InputSystem : MonoBehaviour
{
private CCHY_GameControls_System _input;

public CCHY_GameControls_System input
{
get
{
if (_input == null)
{
_input = new CCHY_GameControls_System();
}
return _input;
}
}
void Start()
{
Debug.LogError($"2 start:{Time.time}");
}

private void OnEnable()
{
Debug.LogError($"1 OnEnable:{Time.time}");

input.Enable();

input.CCHY_KeyboardOperation.Jump.performed += Jump;
input.CCHY_KeyboardOperation.Skill_1.performed += Skill_1;
input.CCHY_KeyboardOperation.Skill_2.performed += Skill_2;
input.CCHY_KeyboardOperation.Skill_3.performed += Skill_3;
}

private void OnDisable()
{
input.CCHY_KeyboardOperation.Jump.performed -= Jump;
input.CCHY_KeyboardOperation.Skill_1.performed -= Skill_1;
input.CCHY_KeyboardOperation.Skill_2.performed -= Skill_2;
input.CCHY_KeyboardOperation.Skill_3.performed -= Skill_3;
}

public void Jump(InputAction.CallbackContext ctx)
{
Debug.LogError($" Press space button {Time.time}");
}

public void Skill_1(InputAction.CallbackContext ctx)
{
Debug.LogError($" Press Skill_1 button {Time.time}");
}

public void Skill_2(InputAction.CallbackContext ctx)
{
Debug.LogError($" Press Skill_2 button {Time.time}");
}
public void Skill_3(InputAction.CallbackContext ctx)
{
Debug.LogError($" Press Skill_3 button {Time.time}");
}
}

Комментарии

Информация по комментариям в разработке