I’m working on the game where I need to count steps for some gameplay features. I’m using InputSystem 1.3.0 and Unity 2020.3.37f1.
I need steps to be counted not only when application is running, but also when it is completely turned off. I’ve managed to do that successfully for android, but I have an issue with iOS. Steps counting for iphone works fine only when application is turned on (it doesn’t matter is it in focus or not). But if I rerun my game, steps counting starts from zero.
I use the following code for iOS:
private void Start()
{
if (StepCounter.current != null)
{
InputSystem.EnableDevice(StepCounter.current);
}
}
private void Update()
{
if (StepCounter.current != null)
{
_stepsLabel.text = $"Steps: {StepCounter.current.stepCounter.ReadValue()}";
}
else
{
_stepsLabel.text = $"Steps: NaN";
}
}
iOSStepCounter.IsAvailable() returns true and iOSStepCounter.AuthorizationStatus returns Authorized.
Also I didn’t forget to enable “Motion usage” option in project settings.
I’m looking forward for any help with this question, thank you!