so I’m trying to setup a main menu screen for my game that will switch to anouther screen to create a character but it i can’t get it to work for some reason, i put up some debug statement s to see where it was getting stuck and it seems to be in the last else statement"there is no player name key"
any help would be greatly appreciated
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
//find the version, maybe move to game settings
public const float VERSION = .1f;
//to delete the.plist
public bool clearPrefs = false;
//level to load
private string _levelToLoad = "";
//the scene that creates a character
private string _characterGeneration = "CharacterGenerator";
//first starting point
private string _firstLevel = "Level1";
// Use this for initialization
void Start ()
{
//stes up a way to deleter the.plist
if(clearPrefs)
{
PlayerPrefs.DeleteAll ();
}
if (PlayerPrefs.HasKey ("ver")) {
Debug.Log ("there is a ver key");
if (PlayerPrefs.GetFloat ("ver") != VERSION)
{
Debug.Log ("saved ver is not same as cur ver");
//upgrade player prefs here
}
else
{
Debug.Log ("saved version is the same as the current vrsion");
//checks for something in the key
if (PlayerPrefs.HasKey ("Player Name"))
{
Debug.Log ("There is a Player Name tag");
//
if (PlayerPrefs.GetString ("PlayerName") == "")
{
Debug.Log ("The player name key does not have anything in it");
//deletes the playerprefs
PlayerPrefs.DeleteAll ();
//sets level to loat to be character generator
_levelToLoad = _characterGeneration;
}
else
{
Debug.Log ("the player name key has a value");
//sets level to loat to be lvl1
_levelToLoad = _firstLevel;
}
}
else
{
Debug.Log ("there is no player name key");
PlayerPrefs.DeleteAll();
_levelToLoad = _characterGeneration;
}
}
}
else
{
Debug.Log ("There is no ver key");
//deletes the playerprefs
PlayerPrefs.DeleteAll();
//gets player key
PlayerPrefs.SetFloat("ver", VERSION);
//sets level to loat to be character generator
_levelToLoad = _characterGeneration;
}
}
// Update is called once per frame
void Update ()
{
if(_levelToLoad == "")
{
return;
//if the level to loat has ready to load
if(Application.GetStreamProgressForLevel(_levelToLoad) == 1)
{
Debug.Log ("level ready");
if(Application.CanStreamedLevelBeLoaded(_levelToLoad))
{
Application.LoadLevel (_levelToLoad);
//SceneManager.LoadScene("CharacterGenerator");
}
}
}
}
}