Hello all - I am trying to read the value of the ambient light sensor in Android.
Here is my class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Android;
using UnityEngine.UI;
public class GetLightData : MonoBehaviour
{
[SerializeField] private Text statusText;
// Start is called before the first frame update
void Start()
{
//var device = InputSystem.AddDevice("MyDevice");
InputSystem.EnableDevice(LightSensor.current);
if(LightSensor.current.enabled) {
statusText.text = "lightsensor is active";
} else {
statusText.text = "lightsensor is not active";
}
}
// Update is called once per frame
void Update()
{
}
}
It throws the following error:
ArgumentNullException: Value cannot be null.
Parameter name: device
.
I tested this on my device where I know an ambient light sensor is present.
Notes:
I installed the new input system from the package manager after receving an error about the InputSystem namespace not existing. I switched “Active Input Handling” to the new input system in player settings, which broke my normal button clicking interactions. I was able to get those working again by switching active input handling to “both” so that’s where I am currently at. Thanks.