I’m having trouble retrieving the Accelerometer value from the CallbackContext. The OnAccelerometer method doesn’t seem to be triggering.
I’ve configured the “Accelerometer” Action along with the Accelerometer binding.
For testing the game, I’m using Unity Remote 5 on my Android phone.
It works fine with Accelerometer.current.acceleration.ReadValue()
using UnityEngine;
using UnityEngine.InputSystem;
public class Test : MonoBehaviour {
private PlayerInput _playerInput;
private void Awake() {
_playerInput = GetComponent<PlayerInput>();
}
private void OnEnable() {
_playerInput.actions["Accelerometer"].performed += OnAccelerometer;
}
private void OnDisable() {
_playerInput.actions["Accelerometer"].performed -= OnAccelerometer;
}
private void OnAccelerometer(InputAction.CallbackContext context) {
var value = context.ReadValue<Vector3>();
Debug.Log($"Accelerometer: {value}");
}
}