title: Using the Android gyroscope in Unity3d, how can I set the initial camera rotation to the initial mobile device rotation?
body: <p>I want to use the Android gyroscope to perform head tracking on the standard First Person Controller of Unity3d. I created a short script that rotates both the parent node and the camera child node of the First Person Controller. The script is attached to the camera.</p>
  
  <p>This script works very well, it rotates the first-person view based on the movements of my mobile device. However, it only works when I hold my phone in a forward looking position when I start my app. If my phone lies flat on the table and I start my app, both the camera and gyroscope rotations are off.</p>
  
  <p>I would like my script to respect the initial device rotation. When I start my app and my device has the screen up, the camera should initially also look up. How can I modify my script to set the camera rotation to the initial mobile device rotation?</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  // Activate head tracking using the gyroscope
  public class HeadTracking : MonoBehaviour {
      public GameObject player; // First Person Controller parent node
      public GameObject head; // First Person Controller camera
  
      // Use this for initialization
      void Start () {
          // Activate the gyroscope
          Input.gyro.enabled = true;
      }
  
      // Update is called once per frame
      void Update () {
          // Rotate the player and head using the gyroscope rotation rate
          player.transform.Rotate (0, -Input.gyro.rotationRateUnbiased.y, 0);
          head.transform.Rotate (-Input.gyro.rotationRateUnbiased.x, 0, Input.gyro.rotationRateUnbiased.z);
      }
  }
  </code></pre>