Skip to content

Instantly share code, notes, and snippets.

@jhorikawa
Created October 6, 2017 14:05
Show Gist options
  • Save jhorikawa/ae1d7243e5927cc1cf401055cdf8b7ac to your computer and use it in GitHub Desktop.
Save jhorikawa/ae1d7243e5927cc1cf401055cdf8b7ac to your computer and use it in GitHub Desktop.
Detect device orientation detection for Unity. It works even if the device rotation is locked.
public void DetectDeviceRotation(){
Vector3 acc = Input.acceleration;
if(Mathf.Abs(acc.x) > Mathf.Abs(acc.y)){
if(acc.x < 0){
Debug.Log("Landscape Left");
}else{
Debug.Log("Landscape Right");
}
}else{
if(acc.y < 0){
Debug.Log("Portrait");
}else{
Debug.Log("Upsidedown Portrait");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment