Game Development Reference
In-Depth Information
this.status = missionStatus.MS_Completed;
Implementing the MissionToken script
The MissionToken class stores the information for an individual mission compon-
ent. This class acts as a container for this abstract data. We give it an ID, a title that
is human readable, and a description. By giving each MissionToken a unique ID,
we give the Mission class a powerful way of tracking the mission progress. This
class is used in a way by which the user adds instances of this component to various
interactive objects that can be manipulated by the player, as shown in the following
code:
Public int id;
Public string title;
Public string description;
Implementing the SimpleLifespanScript
The SimpleLifespanScript class is a simple helper class that can be used in
conjunction with the Instantiate() method to instantiate a GameObject in the
world that will have a specified but finite lifespan. We use it to enable an instance
of a Prefab that is live for a set period of time and then destroys itself as a reward
for completing a mission. By attaching this to the reward that is displayed when a
mission is completed, the prompt is given a set duration on the screen after which it
disappears.
Specifically, the seconds parameter is the time for which the object will survive be-
fore self destruction, as shown in the following code:
Public float seconds
In the update method, we count this value by the actual time elapsed in each frame
(from Timer.deltaTime ). Once this reaches zero, we destroy the object and all
the scripts attached to it (including the simpleLifespanScript ), as shown in the
following code:
Search WWH ::




Custom Search