- Home /
Question by
Raijinn-sama · Jan 18 at 11:20 PM ·
androidmobilemobile devicessensor
Use LightSensor using new InputSystem
I'm currently working on a android game and trying to use the Lightsensor to adjust whether its bright or dark in the game. My problem is that i am getting ArgumentNullException: Value cannot be null. parameter name: device
when calling InnputSystem.EnableDevice
Im using a Google Pixel 3a phone and i have tested the lightning sensor on the phone with a app called sensor test and it recognized when it was getting darker and brighter when i hold my hand over it.
The Light sensor appears in the input debugger (Window > Analysis > Input Debugger; Remote Devices)
Here's the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class LightFunction : MonoBehaviour
{
// Update is called once per frame
void Update()
{
InputSystem.EnableDevice(LightSensor.current);
if (LightSensor.current.enabled)
{
Debug.Log("light: ");
}
}
}
Thanks In Advance!
Comment