- Home /
Screen.orientation api error?
When testing out this code in the api:
https://docs.unity3d.com/ScriptReference/Screen-orientation.html
Error on this line:
Screen.orientation = ScreenOrientation.LandscapeLeft;
Error:
Assets/DeviceChange.cs(186,40): error CS0117:
ScreenOrientation' does not contain a definition for
LandscapeLeft'
Any ideas? I am copying the code from the api so I am confused why it doesn't work.
I get NO problem using that line of code in a new test script. Perhaps you copy pasted in some kind of hidden character? Does autocomplete work? (I copy pasted your sample directly into my test.)
Answer by Bunny83 · Apr 26, 2017 at 07:06 PM
You most likely named one of your classes "ScreenOrientation". That will "hide" the ScreenOrientation enum type. It's highly recommended to rename your type to something else. However if you want to keep it, you have to use the full type name:
Screen.orientation = UnityEngine.ScreenOrientation.LandscapeLeft;
Your answer
Follow this Question
Related Questions
How to have a scene rotate with the device orientation 0 Answers
When are Screen.width and Screen.height updated after changing the Screen.orientation value? 0 Answers
Detect Orientation change at runtime? 0 Answers
Incorrect portrait Screen.orientation after Unity Ad interstitial playback 0 Answers