Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In Unity, how can I freeze the screen in one scene, change scene, and then unfreeze it in the other scene? With freezing the screen I simply mean that it doesn't get updated while it's frozen. With screen I simply mean this: https://i.gyazo.com/10f8673d28da776c064fbb0e716866ad.jpg

I've tried to set Time.timeScale = 0, but that didn't work.

The thing is that I have different screen orientations in the scenes: portrait in the first and landscape in the other. This causes the second scene to twist/ruin the loading screen that was loaded in the first scene. The stuff being initialized in the second scene demands landscape orientation, so I can't just change the screen orientation after everything have been initialized.

I just want to freeze the screen after the loading image has loaded and then unfreeze it after the second scene has been initialized. Is this possible?

This is my code at the moment, generalized:

// Script for the first scene
class firstClass(){
    IEnumerator ChangeScene(){
        // Display loading screen in portrait orientation
        loadingScreen.SetActive(true);
        // Load the second scene
        SceneManager.LoadSceneAsync("secondScene");
    }
}

// Script for the second scene
class secondClass(){
     Start(){
         Screen.orientation = ScreenOrientation.LandscapeLeft; // twists the loading screen :(
         Init(a lot of stuff) // Needs landscape orientation to be initialized properly

         // Init done, hide loading screen
         loadingScreen.SetActive(false);

     }
}

This is how I want it to work:

class firstClass(){
    IEnumerator ChangeScene(){
        // Display loading screen in portrait orientation
        loadingScreen.SetActive(true);
        FreezeScreen();
        SceneManager.LoadSceneAsync("secondScene");
    }
}

class secondClass(){
     Start(){
         Screen.orientation = ScreenOrientation.LandscapeLeft; // doesn't affect the loading screen because the screen is frozen!
         Init(a lot of stuff);
         UnfreezeScreen();
         // Init done, hide loading screen
         loadingScreen.SetActive(false);

     }
}

Here's an illustration: https://gyazo.com/864303465be750b7970636415ddf070d

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
180 views
Welcome To Ask or Share your Answers For Others

1 Answer

void freezeOrientation(bool freezeOrnt = true)
{
    Screen.autorotateToLandscapeLeft = freezeOrnt;
    Screen.autorotateToLandscapeRight = freezeOrnt;
    Screen.autorotateToPortrait = freezeOrnt;
    Screen.autorotateToPortraitUpsideDown = freezeOrnt;
}

Freeze Orientation

freezeOrientation(true);

Un-freeze Orientation

freezeOrientation(false);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...