- Home /
Slide between scenes
Hey guys, I would like to make a scene transition where the first scene slides out of the way showing the second scene behind it. This would require two scenes to be loaded at the same time. Here's an example of what I'm looking to create.
I'm not sure how to go about this and help would be much appreciated. Thanks in advance.
Answer by Santifocus · Sep 17, 2019 at 02:07 PM
There are two ways i can think of one easier but more restricted and one a little harder but should be flexible:
1: You know how the first frame in the second scene looks like so you would make a screenshot of some sort. Then when you intend to change the scene you preload the second scene, when it is done you do some nice transitional UI stuff e.g. a 2D mask that reveals the screenshot you created beforehand, and when the screenshot is fully revealed you jump over to the next scene.
Related but probably not what you are looking for: https://www.youtube.com/watch?v=Oadq-IrOazg
2: You dont know how the first frame of the second scene looks like or it might vary based on different situations. Okay dont take my word for this because i didnt try this. You can load Scenes addatively in other words you can have 2 scenes active at the same time you would then need to acces the two cameras from which the player views the scenes and make use of the "Viewport Rect" attribute on those cameras.
Something like this. (Not tested)
private IEnumerator TransitionCameras()
{
float transitionSpeed = 0.5f;
float transitionPoint = 1;
Camera firstSceneCamera = null; //put your cameras here
Camera secondSceneCamera = null;
secondSceneCamera.rect = new Rect(transitionPoint, 0, 1, 1);
while(transitionPoint > 1)
{
yield return new WaitForEndOfFrame();
transitionPoint -= Time.deltaTime * transitionSpeed;
firstSceneCamera.rect = new Rect(1 - transitionPoint, 0, 1, 1);
secondSceneCamera.rect = new Rect(transitionPoint, 0, 1, 1);
}
secondSceneCamera.rect = new Rect(0, 0, 1, 1);
//Unload old scene here
}
Thanks for the reply. I'll give it a try and let you know if it works.