Class Accelerometer
Input device representing an accelerometer sensor.
Inherited Members
Namespace: UnityEngine.InputSystem
Syntax
public class Accelerometer : Sensor
Remarks
An accelerometer let's you measure the acceleration of a device, and can be useful to control content by moving a device around. Note that the accelerometer will report the acceleration measured on a device both due to moving the device around, and due gravity pulling the device down. You can use GravitySensor and LinearAccelerationSensor to get decoupled values for these.
class MyBehavior : MonoBehaviour
{
protected void OnEnable()
{
// All sensors start out disabled so they have to manually be enabled first.
InputSystem.EnableDevice(Accelerometer.current);
}
protected void OnDisable()
{
InputSystem.DisableDevice(Accelerometer.current);
}
protected void Update()
{
var acceleration = Accelerometer.current.acceleration.ReadValue();
//...
}
}
Properties
acceleration
Declaration
public Vector3Control acceleration { get; }
Property Value
Type | Description |
---|---|
Vector3Control |
current
Declaration
public static Accelerometer current { get; }
Property Value
Type | Description |
---|---|
Accelerometer |
Methods
FinishSetup()
Declaration
protected override void FinishSetup()
Overrides
MakeCurrent()
Declaration
public override void MakeCurrent()
Overrides
OnRemoved()
Declaration
protected override void OnRemoved()