Created
October 6, 2017 14:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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