Game Development Reference
In-Depth Information
public npcCondition initialScore;
9. If a
Player
class can be found, extract the score from the
playerData
component, and store it in the
initialScore
component. Note that we
need to cast the
npcComponent
base reference to
floatData
in order to
access the
_floatData
member for storage.
10. The body of this method works in a manner similar to
SetupMissionTwo
,
where it creates backups of the
QuizPrefab
and
SpawnPoint
lists. It
diverges, however, when five random quiz cards are selected from the
QuizPrefab
list. We directly associate the
card
Prefab with the NPC to be
instantiated as shown in the following code:
objectInteraction objInteraction =
Npc.GetComponent<objectInteraction>();
if (objInteraction)
objInteraction.prefab = quizPrefab;
11. We also pass the ID value from the
QuizPrefab
card into the ID of
QuizNpcHelper
. We use this later when the
CorrectAnswer
pop up looks
up the NPC that instantiated the card. At that time, we locate the NPC by ID
and then pass
doSuccess
into its animator to make it dance as done in level
two.
Congratulations! The
setupLevel3
Prefab is complete. We now have a class that
will randomly pick a state quiz card and randomly spawn NPCs in the world to inter-
act with the player.