Game Development Reference
In-Depth Information
Figure 10-1. Adding levels to the levels list
If you were being really ambitious and made a huge level, one that sprawled on for a long time
and included many more meshes and enemies, it may take a long time to load. Generally, it's not
a good idea to keep the gamer waiting. Today, we're acclimatized by so many time-compressing
technologies offering instant access to media and on-demand services, that waiting times feel longer
than they ever have. To alleviate waiting times and avoid gamer frustration, Unity allows you to load
levels asynchronously, too—that is, to load levels in the background while the gamer is still playing
the game. To do this, the Application.LoadLevelAsync coroutine can be used (see Listing 10-2).
Listing 10-2. Loading a Level Asynchronously
yield return Application.LoadLevelAsync("ABigLevel");
The type of level loading that we've considered so far works well when you need to completely move from
one level to the next in the traditional sense—that is, exiting level X to move to level Y. But sometimes
you'll make games, like large, open-ended RPGs or flight simulators, in which the environment should be
experienced as one continuous and enormous world that stretches on, seemingly forever. In such
games, you don't want a transition or change from one discrete level to the next. You don't want
the user to notice a transition at all. You just want the world to seem complete and integrated, even
though you may have developed it across multiple scene files. In essence, you want to load in a
different scene and add it to the existing one, creating the appearance of a complete and integrated
environment. In this case, you can use the function Application.LoadLevelAdditive or
Application.LoadLevelAdditiveAsync (see Listing 10-3).
Search WWH ::




Custom Search