Game Development Reference
In-Depth Information
Using the setupLevel3 Prefab
The
setupLevel3
Prefab will be activated when the user presses the
popup_Level3Start
button. It will initialize the NPCs for the level, place them in
random locations in the world, and set up the state tracking logic that determines if
the player achieves success. Perform the following steps to use the
setupLevel3
Prefab:
1. Locate the Prefab named
setupLevel2
beneath
_level2
, and rename it
setupLevel3
. Duplicate the
SetupMissionTwo
script from mission two,
and rename the duplicate to
SetupMissionThree
. Place the duplicate in the
folder named
Chapter9
to keep your assets organized.
2. Add an instance of this script to the
setupLevel3
object.
3. Inside
MonoDevelop
, change the class declaration to
SetupMissionThree
so that it matches the name of the script as shown in the following code:
public class SetupMissionThree :
MonoBehavior
4. We will use the same pattern to choose random NPC locators as we did for
the QuizNpc locators in mission two. We will remove the
CorrectPopups
list,
because each pop up will have a unique, correct pop up already associated
with it in the editor.
5. At this point, open up
PopupPanel.cs
, and add the following line of code:
Public int id;
6. This ID will be used by the pop up to locate the NPC that dispatched it so that
its animation can be updated on success.
7. In
LEVEL3
, we note the successful pass condition is when 2,500 points have
been earned in addition to the points from levels one and two. In order to de-
termine this, we need to remember the score at the beginning of the level so
that we can calculate the delta.
8. At the top of
SetupMissionThree
, add an
initialScore
variable of type
npcCondition
. Since the level's complete processing will be handled by
npcDecisionMgr
, we need to store the score in a datatype that this system
can operate on: