Class Sensor
Base class representing any sensor kind of input device.
Inherited Members
Namespace: UnityEngine.InputSystem
Syntax
public class Sensor : InputDevice
Remarks
Sensors represent device environmental sensors, such as Accelerometers, Gyroscopes, GravitySensors and others.
Unlike other devices, sensor devices usually start out in a disabled state in order to reduce energy consumption (i.e. preserve battery life) when the sensors are not in fact used. To enable a specific sensor, call EnableDevice(InputDevice) on the device instance.
// Enable the gyroscope.
InputSystem.EnableDevice(Gyroscope.current);
Sensors are usually sampled automatically by the platform at regular intervals. For example, if a sensor is sampled at 50Hz, the platform will queue an event with an update at a rate of roughly 50 events per second. The default sampling rate for a sensor is usually platform-specific. A custom sampling frequency can be set through samplingFrequency but be aware that there may be limitations for how fast a given sensor can be sampled.
Properties
samplingFrequency
The frequency (in Hertz) at which the underlying sensor will be refreshed and at which update events for it will be queued.
Declaration
public float samplingFrequency { get; set; }
Property Value
Type | Description |
---|---|
Single | Times per second at which the sensor is refreshed. |
Remarks
Note that when setting sampling frequencies, there may be limits on the range of frequencies supported by the underlying hardware/platform.
To support querying sampling frequencies, a sensor device must implement UnityEngine.InputSystem.LowLevel.QuerySamplingFrequencyCommand. To support setting frequencies, it must implemenet SetSamplingFrequencyCommand.