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!

Screen.orientation = ScreenOrientation.LandscapeLeft;

//Portrait//PortraitUpsideDown//LandscapeRight//AutoRotation