Game Development Reference
In-Depth Information
• A dictionary to record the scenes the player has been to and the last position they
were in that scene
Simple enough, but to avoid unnecessary code duplication I have also added some helper
methods to the GameState class to manage and simplify the use of the LastS-
cenePositions dictionary (to save time later).
So add the following code to the end of the GameState class:
public static Vector3 GetLastScenePosition(string
sceneName)
{
if
(GameState.LastScenePositions.ContainsKey(sceneName))
{
var lastPos =
GameState.LastScenePositions[sceneName];
return lastPos;
}
else
{
return Vector3.zero;
}
}
public static void SetLastScenePosition(
string sceneName, Vector3 position)
{
if
(GameState.LastScenePositions.ContainsKey(sceneName))
{
GameState.LastScenePositions[sceneName] =
position;
}
else
{
GameState.LastScenePositions.Add(sceneName,
position);
Search WWH ::




Custom Search