Class Sensor
Base class representing any sensor kind of input device.
Inherited Members
Namespace: UnityEngine .InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public class Sensor : InputDevice
Remarks
Sensors represent device environmental sensors, such as Accelerometers, Gyroscopes,
Gravity
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 Enable
// 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 sampling
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 |
---|---|
float | 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 Query
Exceptions
Type | Condition |
---|---|
Not |
Thrown when reading the property and the underlying sensor does not support querying of sampling frequencies. |