Hello, I would like to count the user’s real world steps in my mobile game but I’m having a hard time finding anything on the step counter in Unity’s InputSystem. It seems there are no tutorials on this, and most people seem to give up and use third party systems. I’ve been left trying to pillage code off the forums, but it doesn’t really work. And the unity documentation is sorely lacking examples.
Here is what I have so far. The first block is, I think, intended to check if we have the step counter permissions on Android. I don’t know how to go about this on other platforms. this doesn’t seem to work in tethered mode, as I don’t get a popup.
private void Start()
{
#if PLATFORM_ANDROID
if (!Permission.HasUserAuthorizedPermission("android.permission.ACTIVITY_RECOGNITION"))
{
Permission.RequestUserPermission("android.permission.ACTIVITY_RECOGNITION");
}
#endif
}
I am then trying to activate the counter using:
if (!Application.isEditor) { InputSystem.EnableDevice(StepCounter.current); }
And I am then trying to get it to print the steps using this. I’m not getting anything except my default text, so I assume this never fires. Even though I shook it until the cable fell out
void FixedUpdate()
{
if (StepCounter.current.enabled)
{
counter[3].text = StepCounter.current.stepCounter.ReadValue().ToString();
}
}