docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Query sensors in code

    To determine whether a particular sensor is present, you can use its .current getter.

    Warning

    It looks like the sample you are looking for does not exist.

    Unlike other devices, sensors are disabled by default. To enable a sensor, call InputSystem.EnableDevice.

    Warning

    It looks like the sample you are looking for does not exist.

    To disable a sensor, call InputSystem.DisableDevice.

    Warning

    It looks like the sample you are looking for does not exist.

    To check whether a sensor is currently enabled, use InputDevice.enabled.

    Warning

    It looks like the sample you are looking for does not exist.

    Sample sensor frequency

    Sensors sample continuously at a set interval. You can set or query the sampling frequency for each sensor using the samplingFrequency property. The frequency is expressed in Hertz (number of samples per second).

    Warning

    It looks like the sample you are looking for does not exist.

    Measure a device's acceleration

    Use the accelerometer to measure the acceleration of a device. This is useful to control content by moving a device around. It reports the acceleration measured on a device both due to moving the device around, and due to gravity pulling the device down. You can use GravitySensor and LinearAccelerationSensor to get separate values for these. Values are affected by the Compensate Orientation setting.

    The following code traces all input events on the Accelerometer.current device.

    Warning

    It looks like the sample you are looking for does not exist.

    Determine the orientation of a device

    Use the attitude sensor to determine the orientation of a device. This is useful to control content by rotating a device. Values are affected by the Compensate Orientation setting.

    On Android devices, there are two types of attitude sensors: RotationVector and GameRotationVector.

    Some Android devices have both types of sensor, while other devices may only have one or the other type available. These two types of attitude sensor behave slightly differently to each other. You can read about the differences between them here.

    Because of this variety in what type of rotation sensors are available across devices, when you require input from a rotation sensor on Android devices, you should include code that checks for your preferred type of rotation sensor with a fallback to the alternative type of rotation sensor if it is not present. For example:

    Warning

    It looks like the sample you are looking for does not exist.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)