读加速计传感器(精密)
准确读取加速计传感器。
此示例分配内存:
void Update()
{
//Get Precise Accelerometer values
Vector3 accelValue = preciseAccelValue();
Debug.Log("PRECISE X: " + accelValue.x + " Y: " + accelValue.y + " Z: " + accelValue.z);
}
Vector3 preciseAccelValue()
{
Vector3 accelResult = Vector3.zero;
foreach (AccelerationEvent tempAccelEvent in Input.accelerationEvents)
{
accelResult = accelResult + (tempAccelEvent.acceleration * tempAccelEvent.deltaTime);
}
return accelResult;
}
这个例子并没有分配内存:
void Update()
{
//Get Precise Accelerometer values
Vector3 accelValue = preciseAccelValue();
Debug.Log("PRECISE X: " + accelValue.x + " Y: " + accelValue.y + " Z: " + accelValue.z);
}
Vector3 preciseAccelValue()
{
Vector3 accelResult = Vector3.zero;
for (int i = 0; i < Input.accelerationEventCount; ++i)
{
AccelerationEvent tempAccelEvent = Input.GetAccelerationEvent(i);
accelResult = accelResult + (tempAccelEvent.acceleration * tempAccelEvent.deltaTime);
}
return accelResult;
}
请注意,这不会被过滤。请查看此处了解如何平滑加速度计值以消除噪音。