Game Development Reference
In-Depth Information
},
};
As we are now using a
struct
method for our destination information, we also need to
update the
GetRouteInfo
method to access the dictionary correctly and return the
routes' description if found; we do this using the following code:
public static string GetRouteInfo(string destination)
{
return RouteInformation.ContainsKey(destination) ?
RouteInformation[destination].RouteDescription :
null;
}
With that in place, all we need to do is check whether the
CanTravel
flag is true when
the system requests, and if you're allowed to travel, update the
CanNavigate
method
with the following code:
public static bool CanNavigate(string destination)
{
return RouteInformation.ContainsKey(destination) ?
RouteInformation[destination].CanTravel :
false;
}
Here, we simply look at the destination from our route information and return with in-
formation on whether the player is allowed to travel there or not.
Now, when you try to go to the cave, you won't get the prompt from
NavigationMan-
ager
whether you want to travel to it or not.
To finish off, we just need to get the Greybeard NPC to listen for the message that the
player will leave and then start his most troublesome conversation. So, remove the
Mes-
sagingClientReceiver
script (that was created in the
Messaging
section) from the
left border (the cave) that you set up earlier and add it to the Greybeard NPC game object.
Now, Greybeard is subscribing to and receiving the messages for the player leaving. Next,
update the
MessagingClientReceiver
script (in the
Messaging
folder under