Graphics Reference
In-Depth Information
14.1 Main Menu
Interstellar Paranoids has a main menu scene and two game levels. The main menu is con-
tained in a single scene that uses the scene manager component (as discussed in Chapter 4,
Section 4.10) to load the first game scene. From there, the scene manager is used to manage
level count and level loading.
The main menu scene has a single camera named Main Camera. The main menu script
is attached to it as a component, rendering the menu and dealing with its interaction. This is
the same script that is used in all of the example games menu screens, but it is the only one
that adds a two-player mode and displays an extra button on the menu to start it.
On the script component MainMenuController, when the string variable coopGame-
StartScene has something in it (entered in through the Unity editor Inspector window), an
extra button is displayed on the menu with the label START CO-OP.
he MainMenuController.cs script is outlined in full in Chapter 10 of this topic, but
to add some context, here is the code that adds the extra button to the menu:
if(coopGameStartScene!="")
{
if(GUI.Button(new Rect(0, 250, 300, 40 ),"START CO-OP"))
{
PlayerPrefs.SetInt( "totalPlayers", 2 );
LoadLevel( coopGameStartScene );
}
When the button is clicked, the totalPlayers prefs key is set to 2. The game will pick up
on this and add the extra player when it is required to. The game is loaded in the same way
as the single-player game, through the LoadLevel() function of the menu script.
14.2 Game Scenes
Each game level's environment and enemy objects are contained in single scenes, although
some core game elements persist throughout the game such as the game controller, player,
and camera. This means that the game only needs to run its main setup functions once to
create the player and arrange the core elements. They persist until the game ends, when
they are destroyed before the main menu scene reloads.
There are two levels in the example game, but they have the exact same Hierarchy
structure in both scenes. The Hierarchy contains
Directional light
Level
Models that make up the environment—in this game, this is mostly instances
of attack pattern prefabs (containing waypoints and spawners for enemies)
LevelSetup
ScrollStopper
SoundController
Search WWH ::




Custom Search