private void Update() { if (_calibrating) { // While calibrating, continuously sample the gyroscope and wait for it to fall below a motion // threshold. When that happens, or a timeout is exceeded, grab a sample from the rotation sensor and // use that as the reference rotation. SensorFrame frame = _wearableControl.LastSensorFrame; bool didWaitEnough = Time.unscaledTime > _calibrationStartTime + _minCalibrationTime; bool isStationary = frame.angularVelocity.value.magnitude < _calibrationMotionThreshold; bool didTimeout = Time.unscaledTime > _calibrationStartTime + _maxCalibrationTime; if ((didWaitEnough && isStationary) || didTimeout) { _referenceRotation = frame.rotation; _calibrating = false; // Pass along the reference to the rotation matcher on the widget. _widgetRotationMatcher.SetRelativeReference(frame.rotation); if (CalibrationCompleted != null) { CalibrationCompleted.Invoke(); } // Spawn the first target after calibration completes. Invoke("SpawnTarget", _spawnDelay); } } }
void Update() { if (_calibrating) { SensorFrame frame = _wearableControl.LastSensorFrame; bool didWaitEnough = Time.unscaledTime > _calibrationStartTime + 5; bool isStationary = frame.angularVelocity.value.magnitude < 1; bool didTimeout = Time.unscaledTime > _calibrationStartTime + 10; if ((didWaitEnough && isStationary) || didTimeout) { _referenceRotation = frame.rotation; _calibrating = false; // Pass along the reference to the rotation matcher on the widget. _matcher.SetRelativeReference(frame.rotation); if (CalibrationCompleted != null) { CalibrationCompleted.Invoke(); } } } }