Game Development Reference
In-Depth Information
public static void GoBack()
{
var backlocation = PreviousLocation;
PreviousLocation = Application.loadedLevelName;
FadeInOutManager.FadeToLevel(backlocation);
}
All this function does is that it gets the previous location to a separate variable, sets the
current scene as the previous location (so if you go back again, you will return to the
scene you just went back from), and then transitions to the previous scene.
Now that our navigation manager has the ability to go back, we can return to our shop
scene to enable the user to leave the shop and go back to the real world.
Next, create another script named BackButton and place it in As-
sets\Scripts\Shop with the following contents, which just calls the new Naviga-
tion method:
using UnityEngine;
public class BackButton : MonoBehaviour {
void OnMouseDown()
{
NavigationManager.GoBack();
}
}
Attach the preceding script to the BackButton game object in the shop scene. Now, the
player can click on the back button and leave the shop. Granted that this can only work
once you enter the shop from another location, so let's look at how to get into the shop
now.
Search WWH ::




Custom Search