Progamatically lock the screen orientation?
I am making a game for android and I want to either lock the screen orientation in portrait or in landscape which the user would be able to change in the settings menu. To do this I figure I need to lock the orientation in the chosen orientation via script, I figured that the user pressing the button would simply turn a bool true or false and depending on the status of the bool it will lock the screen orientation in the appropriate orientation but how do would I actually lock the screen orientation in code? Thank You!
Answer by JigneshKoradiya · Apr 09, 2016 at 07:08 AM
Screen.orientation = ScreenOrientation.LandscapeLeft;
//Portrait//PortraitUpsideDown//LandscapeRight//AutoRotation
I can't get it to work, perhaps I'm using it wrong, I have used it in an update loop on a script attached to the main camera ($$anonymous$$ain camera because I plan on changing the camera angle depending on the orientation) and that's about it for the script.
I thought that maybe i need to set up the orientation settings in the player tab under project settings in a specific way so the program can lock it in the orientation in the code.
Thanks
Never $$anonymous$$d, it works fine, it is just doesn't work in unity editor and unity remote. Thanks!