Game Development Reference
In-Depth Information
4. If there are any flag choices in PlayerData at this point, we clear them. This
is a reasonable assumption to make in level 1 as it is the first gameplay level
that we encounter. The subsequent levels will access these values when
populating their scenes. Clearing the flagChoices array before use is a
good defensive practice so that we don't accidentally end up with more flag
instances in the level than intended:
if (pd.flagChoices.Count > 0)
pd.flagChoices.Clear();
5. In the SetupMission() method, on line 92, as the initial set of flags are
chosen, we store the flag index in the playerData component. Here, they
will be carried with the player through level 2 and level 3:
if (pd != null)
pd.flagChoices.Add (index);
6. Now that the first mission has been successfully updated to store flag choices
in PlayerData , we shall now move our attention towards refactoring level 2
and level 3 to use this data.
7. In the Start() method of the SetupMissionTwo script, while we are iter-
ating over the flags, we check if there is a PlayerData component on the
player. If one can be found, we assign the flag index from the list in Player-
Data to the variable index rather than a randomly assigned one:
if (pd != null)
index = pd.flagChoices[k];
Congratulations! This completes the required updates for level 2. Now, when starting
the game and selecting NEW , level 1 will be shown initially, and upon completion,
the game will dynamically load level 2. Let's continue updating the code in the same
light as we integrate and refactor level 3.
Search WWH ::




Custom Search