Unity3d the setting of the Institute of automatic rotation the default rotation direction of the screen __unity

Source: Internet
Author: User


As shown in the following illustration, you can choose this option when dealing with the default rotation direction of the screen, which is 4 directions up or down.

The planning requirement is that the game uses a horizontal screen, but requires support in two directions to automatically rotate, as shown in the following figure, my settings are like this.

Default orientation* Auto Roation indicates that the game supports automatic rotation of the screen, but only if the phone does not lock the screen rotation function.

Landscape right and landscape left indicate that the mobile screen only supports automatic rotation in two directions across the screen.

Here is the problem, since the two-direction automatic rotation is set, there is bound to be a default direction. Unity's default direction, however, is that landscape left is the square of the screen on the left-hand side of the mobile home. Most iOS games are in this direction, but there may be a problem with Android, because there is a back button in the lower left corner of the Android screen, if your game is horizontal, and if your game area is in the lower right corner, then the player will probably point to the return button when playing, Then the user experience is lowered.

So the plan is to let the Android version have the default positive direction so that the screen is on the right side of the home, but it must also support the automatic rotation of the horizontal screen. But the unity of the panel is not set with automatic rotation, and set the parameters of the default direction ... I thought about assigning it to the code, so I had the following code. Seems to solve the problem is not perfect, because unity boot has a splash screen, but the splash screen is awake before the execution, so although in awake set the screen direction, but the direction of the launch screen is indeed read projectsetting.

void Awake ()
{
    //Set the screen positive direction screen.orientation = Screenorientation.landscaperight on the right side of the home key
    ;
}
 
void Start ()
{
    //Set the screen to rotate automatically, and place the supported direction
    screen.orientation = screenorientation.autorotation;
    Screen.autorotatetolandscapeleft = true;
    Screen.autorotatetolandscaperight = true;
    Screen.autorotatetoportrait = false;
    Screen.autorotatetoportraitupsidedown = false;
}



So, I set the default square to the right side of the home button directly inside the setting.

In the awake or Start method, the problem is solved perfectly by setting it to support the horizontal screen rotation.

void Start ()
{
    //Set the screen to rotate automatically, and place the supported direction
    screen.orientation = screenorientation.autorotation;
    Screen.autorotatetolandscapeleft = true;
    Screen.autorotatetolandscaperight = true;
    Screen.autorotatetoportrait = false;
    Screen.autorotatetoportraitupsidedown = false;
}



This article fixed link: http://www.xuanyusong.com/archives/2871


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.