Hello top-man:
I wan to use WASD for control camera, this is my code:
private RefugeeCharacterInput _input; // Class Generated by Unity Input System
private void Awake()
{
_input = new RefugeeCharacterInput();
}
private void OnEnable()
{
_input.Building.Enable();
_input.Gameplay.Disable();
}
private void OnDisable()
{
_input.Building.Disable();
_input.Gameplay.Enable();
}
private void Update()
{
var pos = transform.position;
Debug.Log(_input.Building.Horizontal.triggered);
Debug.Log(_input.Building.Horizontal.WasPressedThisFrame());
if (_input.Building.Horizontal.WasPressedThisFrame()) {
if (_input.Building.Horizontal.ReadValue<float>() > 0) {
pos.x += speed * Time.deltaTime;
} else {
pos.x -= speed * Time.deltaTime;
}
}
if (_input.Building.Vertical.WasPressedThisFrame()) {
if (_input.Building.Vertical.ReadValue<float>() > 0) {
pos.y += speed * Time.deltaTime;
}
else {
pos.y -= speed * Time.deltaTime;
}
}
}
I found when I press A
or D
(horizontal key) the _input.Building.Horizontal.triggered is ture, but WasPressedThisFrame always false.
Please help me, thanks.