Suppose so to facilitate:

if(autorotate){включаем автоповорот, или как-нибудь поставить галочки на Landscape в player settings} else галочки убираем с landscape. 

I attached the generated ScreenOrient script to MainCamera.

 void Update { if( Input.deviceOrientation == DeviceOrientation.FaceUp) { //вот тут хочу сделать только портретную ориентацию //deviceOrientation = Portrait. Но не понимаю как. } } 

Those. when the phone put the screen up, switched to portrait. The main thing in the script is how forced to turn the screen I need to know. Thank. And I apologize, if it is not clearly explained, did not describe.

  • Have you ever tried to find an answer? Google gives the correct answer the first link. - RiotBr3aker
  • If you're talking about ScreenOrientatio.Landscape, etc., then it doesn't work - maq
  • What does “not working” mean? Give the code, describe the problem. - RiotBr3aker
  • I attached the generated ScreenOrient script to MainCamera. void Update {if (Input.deviceOrientation == DeviceOrientation.FaceUp) {// here I want to do only portrait orientation // deviceOrientation = Portrait. But I do not understand how. }} Ie when the phone put the screen up, switched to portrait. The main thing in the script is how forced to turn the screen I need to know. Thank. And I apologize, if it is not clearly explained, did not describe. - maq

1 answer 1

As I indicated in the comments: this issue is resolved by peering into the documentation.

Screen.orientation

Specifies logical orientation of the screen.

Default value is taken from the 'Default Orientation' in Player Settings.

ScreenOrientation :

enter image description here


 void Update() { if(Input.deviceOrientation == DeviceOrientation.FaceUp) { Screen.orientation = ScreenOrientation.Portrait; } } 

I think it is obvious that this code will only work in the build on smartphones, the editor or Unity Remote will not work.