Game Development Reference
In-Depth Information
GameState.GetLastScenePosition(Application.loadedLevelName);
if (lastPosition != Vector3.zero)
{
transform.position = lastPosition;
}
}
The previous code simply looks for a last position for the current scene, and if there is
one, it moves the player to it.
Similarly, when closing the scene, we just need to store the last position. To do this, we
add an OnDestroy method as follows and save the player's current position:
void OnDestroy()
{
GameState.SetLastScenePosition(
Application.loadedLevelName, transform.position);
}
Finally, we need our NavigationManager script to reset the new flag when the player
finally returns home. So update the NavigationManager script's NavigateTo
method with the following code:
public static void NavigateTo(string destination)
{
if (destination == "Home")
{
GameState.playerReturningHome = false;
}
FadeInOutManager.FadeToLevel(destination);
}
Now when the NavigationManager script detects that the destination is the Home
scene, it will update the flag to false in the GameState class.
Search WWH ::




Custom Search