Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

playerprefs, save slots not saving/loading?

$
0
0
hey gang trying to set up a basic 3 save slot system using playprefs for i'm not worried about file security or anything with this project, I have 3 slots that you can choose and save to but when you restart the game the data dosn't load load :( all seems to wok but not getting a file name displayed when i restart the game :) should load only the file name so player know witch of the 3 files contain a saved game :) NewGame CS: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class NewGame : MonoBehaviour { public GameFileAccount GameFileAccountCS; int SaveSlot1 = 1; int SaveSlot2 = 2; int SaveSlot3 = 3; public int fileToUse; public string FileName1; public string FileName2; public string FileName3; public Text FileName1txt; public Text FileName2txt; public Text FileName3txt; public Text FileNametxt; public GameObject AreYouSureOverRide; public GameObject FileGameName; // Start is called before the first frame update void Start() { FileName1 = PlayerPrefs.GetString("FileName" + SaveSlot1); FileName2 = PlayerPrefs.GetString("FileName" + SaveSlot2); FileName3 = PlayerPrefs.GetString("FileName" + SaveSlot3); FileName1txt.text = FileName1; FileName2txt.text = FileName2; FileName3txt.text = FileName2; } public void selectFile01button() { if (FileName1 == null) { Debug.Log("File Selceted 1"); FileGameName.SetActive(true); fileToUse = 1; GameFileAccountCS.fileToUse = fileToUse; } if (FileName1 != null) { FileGameName.SetActive(true); fileToUse = 1; GameFileAccountCS.fileToUse = fileToUse; } } public void selectFile02button() { if (FileName2 == null) { FileGameName.SetActive(true); fileToUse = 2; GameFileAccountCS.fileToUse = fileToUse; } if (FileName2 != null) { AreYouSureOverRide.SetActive(true); fileToUse = 2; GameFileAccountCS.fileToUse = fileToUse; } } public void selectFile03button() { if (FileName3 == null) { FileGameName.SetActive(true); fileToUse = 3; GameFileAccountCS.fileToUse = fileToUse; } if (FileName3 != null) { AreYouSureOverRide.SetActive(true); fileToUse = 3; GameFileAccountCS.fileToUse = fileToUse; } } public void newgameFile() { string Lives = "0"; string Coins = "0"; string NewGameName = FileNametxt.text; string MaxHealth = "10"; string MaxMagic = "10"; string Health = "10"; string Magic = "10"; string UnlockedWorlds = "1"; string checkpoint1world1 = "1"; string checkpoint2world1 = "1"; Application.LoadLevel("SampleScene"); PlayerPrefs.SetString(NewGameName + fileToUse, ""); PlayerPrefs.SetString(MaxHealth + fileToUse, ""); PlayerPrefs.SetString(MaxMagic + fileToUse, ""); PlayerPrefs.SetString(Health + fileToUse, ""); PlayerPrefs.SetString(Magic + fileToUse, ""); PlayerPrefs.SetString(Lives + fileToUse, ""); PlayerPrefs.SetString(checkpoint1world1 + fileToUse, ""); PlayerPrefs.SetString(checkpoint2world1 + fileToUse, ""); PlayerPrefs.SetString(UnlockedWorlds + fileToUse, ""); PlayerPrefs.Save(); GameFileAccountCS.LoadGame(); // LoadSellectedGame } }

Viewing all articles
Browse latest Browse all 1333

Trending Articles