Game Development Reference
In-Depth Information
Testing your Save and Load functions
As a simple test for our saving and loading functions, we can add a basic menu to our
game. So, create a new scene named MainMenu in Assets\Scenes and a new script
called MainMenu in Assets\Scripts and replace its contents with the following
code:
using UnityEngine;
[ExecuteInEditMode]
public class MainMenu : MonoBehaviour {
bool saveAvailable;
void Start()
{
saveAvailable = GameState.SaveAvailable;
}
}
Here, we simply start by using a variable to see whether we have a saved file when the
menu is loaded.
Then, we just add an OnGUI method as follows:
void OnGUI () {
GUILayout.BeginArea(new Rect((Screen.width / 2) -
100,(Screen.height / 2) - 100, 200,200 ));
if(GUILayout.Button("New Game"))
{
NavigationManager.NavigateTo("Home");
}
GUILayout.Space(50);
if (saveAvailable)
{
if (GUILayout.Button("Load Game"))
{
GameState.LoadState(() =>
{
Search WWH ::




Custom Search