Search code examples
c#unity-game-enginegame-engineaccelerometerandroid-sensors

SystemInfo.supportsAccelerometer returning false with Unity Remote?


when i try to understand status of device accelerometer support i use : SystemInfo.supportsAccelerometer

this value is false but im sure my device accelerometer works.the code is in below.

thanks a lot for your helps.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class GyroTest : MonoBehaviour {
    public Text Xt;
    public Text Yt;
    public Text Zt;
    private float XX;
    private float YY;
    private float ZZ;
    private bool testvar;

    void Start()
    {
        testvar = SystemInfo.supportsAccelerometer;
        Debug.Log("WXWXWXWXW:: " + testvar.ToString());

        if (SystemInfo.supportsAccelerometer)
        {
            Debug.Log("Device Support Accelometer ");
        }
        else
        {
            Debug.Log("Device Not Support Accelometer ");
        }
    }
    void Update () {

        XX = Input.acceleration.x;
        YY = Input.acceleration.y;
        ZZ = Input.acceleration.z;
        Xt.text = XX.ToString();
        Yt.text = YY.ToString();
        Zt.text = ZZ.ToString();

    }


}

Solution

  • I test my code on my device with Unity Remote version 5

    SystemInfo.supportsAccelerometer does not work with Unity Remote. It will always return false when used via the Editor and Unity Remote. To use SystemInfo.supportsAccelerometer, build and run the app on the Android device itself. It should work on the the device when it is built. If it still return null on the Android device, file for a bug report because it shouldn't.