Is this an anime blog?
I think that everyone who watched at least one anime series noticed a small part in the middle, which usually serves to jump between the scenes and the ad unit - bumper (Japanese - アイキャッチ aikyatchi). The picture from the title of this post is such a transition in “New Game!" title about a small game studio. Oh yes, since this is a blog about Unity, then we will consider the design of the transition between the scenes in it. =)
The scenes in Unity are the basic unit of dividing the game into parts, and the transition between them is not complicated by itself. The transition is implemented through the SceneManager class, using the LoadScene() or LoadSceneAsync() methods. But without additional decoration, these transitions will be sharp, and this will look strange. Let’s try to smooth this transition, adding a little visual appeal to the project.
The scheme is quite simple: both scenes between which the transition is made should be visually identical at the time of unloading the previous one and loading the next. Usually, such a transition organized through the animation of some scene elements. For example, in this post, we use a black screen (the component responsible for this effect will be a black picture). The previous scene should gradually go black, and the next one smoothly appears from it.
The word animation hints at the use of the mechanism in Unity called "Mecanim.“ If you are not very familiar with it, then you can read (or even better use it as an exercise) the previous post "State Template,“ in which, for training purposes, this mechanism used to create a state machine without animation.
Make the transition between the three scenes through a blackout. The first scene appears instantly and, after 2 seconds, goes into the second. The transitions between the second and third are looped and performed smoothly by click.
Build Settings
Canvas
with the name SceneTransition
. Set Render Mode - Screen Space - Camera
and add the Main Camera
. Set Order in Layer
to 999
, so its always on top of other elementsImage
to SceneTransition
and name it Fade
. Completely black, covering the entire screen area. You can turn it off so that it does not block the screenAnimations
Animation
tab. After selecting Fade
, click Create
button and create FadeIn
animation, also create FadeOut
animation.FadeIn
animation. Select the FadeIn
asset. Remove the Loop Time
check. Select a Fade
object. On the Animation
tab, push the Enable/Disable keyframe recording mode
button and enable action recording. Enable Image
component. Move time mark on the Animation
tab to 1 second. In color-chooser set alpha = 0
. Disable Image
component. On the Animation
tab, disable action recording. Checking the animation of the smooth appearance of the UI from dimming.FadeOut
animation but in reverse order: enable Image
, an alpha channel from 0 to 100
. Practice on this step by yourselfAnimator
tab, add a FadeOut
trigger. Add a transition between FadeIn and FadeOut
. On new transition, disable Has Exit Time
and set Transition duration
to 0. In Conditions
, add created trigger FadeOut
.TransitionHandler
witch will be used on the end of FadeOut
animation
|
|
TransitionHandler
script to Fade
object. At the end of FadeOut
animation, add Event
. Choose FadeOutFinished()
function from the TransitionHandler
scriptAnimation
tab looks like thatPrefab
from SceneTransition
objectBootScene
wich will start transition to FirstScene
after 2 seconds
|
|
BootScene
. Add SceneTransition
prefab. Set Main Camera to canvas component. Write the next scene name, "FirstScene."
Disable fade-in animationBootHandler
. After that, add a script from step 1. Set up animator
BootScene
must have fade animation before the transitionClickHandler
script for other scenes, which handle transition by mouse click
|
|
"FirstScene"
. Add SceneTransition
prefab. Set "Main camera." Set next scene name - SecondScene
ClickHandler
. After that, add a script from step 5. Set up animator
SecondScene
. Do all steps from FirstScene
setup, exclude next scene name; it must be - "FirstScene"
After all our manipulations, we got a prefab for transition configuration between scenes. It is unlikely that you will use it for production since the synchronous scene loading used is not a very nice solution. And you also need to fine-tune the transition conditions. Also, you need to think about stopping the game at the time the animation starts. And it is desirable to make the animations themselves more interesting. For example, in Homescapes(Playrix), the transition between loading resources and launching the menu is hidden behind a camera descending along the wall of the house. However, after repeating these steps with your own hands, you should have an idea of how to make the transitions beautiful. See you next time! =)