讀加速計感測器(精密)
準確讀取加速計感測器。
此示例分配記憶體:
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;
}
請注意,這不會被過濾。請檢視此處瞭解如何平滑加速度計值以消除噪音。