title: Unity - Gyroscope - Rotation Around One Axis Only
body: <p>I'm using Unity to make a game that uses the Gyroscope. I am trying to detect the rotation of the device around the axis that goes through the screen, I'm assuming it's the Z-axis in Unity Space. I tried using <code>Input.gyro.attitude.eulerAngles.z</code> but it doesn't stay constant when tilting the device around the other axes, I want it to stay constant so that only the "Z-axis" determines the rotation of a car's steering wheel, for example. How can I implement this?</p>
  
  <p><strong>EDIT:</strong>
  I tried doing something else. I used <code>Input.gyro.rotationRateUnbiased</code> instead of <code>Input.gyro.attitude.eulerAngles</code></p>
  
  <p>Here's the code:</p>
  
  <pre><code>    Vector3 gInput = Input.gyro.rotationRateUnbiased;
      gyroEuler += gInput * Time.deltaTime * Mathf.Rad2Deg;
  
      float rollAngle = gyroEuler.z;
  
      while (rollAngle &lt; 0)
      {
          rollAngle += 360;
      }
      while (rollAngle &gt; 360)
      {
          rollAngle -= 360;
      }
  </code></pre>
  
  <p>But <code>gyroEuler</code> will be set to <code>(0, 0, 0)</code> regardless of the devices orientation at the start of the game so the device orientation will not be known in the beginning and also <code>Input.gyro.rotationRateUnbiased</code> is very inaccurate. I want to rotate the screen the way many games, like <em>Temple Run 2</em>, do but I want to be able to rotate it 360 degrees and get that angle of rotation.</p>