I want to rotate an object (cube for example) all angles by tilting the Android device. I tried various code snippets online and none of them seem to work as needed. Can someone help by providing code that will do this properly?
You’ll need to enable gyro just in case first:
void Start () {
gyro = Input.gyro;
if(!gyro.enabled)
{
gyro.enabled = true;
}
}
then:
void Update ()
{
gameObject.transform.rotation = gyro.attitude;
}
That’s it. After this you will have your object rotating based on phone orientation in space. You will probably have to do a lot of tweaks based on what you want to accomplish in your game/app.