Game Development Reference
In-Depth Information
Leaving the shop
The player can purchase items from the shop (actually, they can buy anything as it's all
free at the moment), but they are stuck in the shop, the doors and windows are barred, and
the owner has a very stern face.
As the shop could be used from anywhere in the game, it would not make much sense to
navigate through all the scenes of the game in a cycle to go back to the earlier scene. So,
we need to add the ability to go back to the previous location the player was in, the place
where his shop is located.
To implement this, we need to make a minor modification to the navigation manager to re-
member the last place where it was. Open the NavigationManager script from As-
sets\Scripts\Navigation and first add a new using statement to the beginning
of the class, as follows:
using System.Collections.Generic;
using UnityEngine;
This will quickly enable us to discover what the current scene is. Next, add the following
static property:
private static string PreviousLocation;
Then, in the NavigateTo method, we need to store the scene the player is travelling
from before we change it; to do this, add the following line:
public static void NavigateTo(string destination)
{
PreviousLocation = Application.loadedLevelName;
if (destination == "Home")
{
GameState.playerReturningHome = false;
}
FadeInOutManager.FadeToLevel(destination);
}
Finally, we need to add a function to enable the scenes to tell the navigation manager to
go back to the previous scene; this can be done using the following lines of code:
Search WWH ::




Custom Search