- Home /
How do you save data and load data on iOS, Android, and Blackberry
I am making a iOS game and when I tried to put the sample code of saving and loading (persistent data) tutorial on iOS, it didn't work. I have tried using the iOS project Documents data path, change my .dat files to .xml files. and using playerprefs. I don't know what to do know. Could anybody help me on this? This is specifically meant for iOS. Thanks in advance! PLEEEEEASEEEE RESPOND IF YOU KNOW HOW TO FIX THIS!!! This is my current code by the way ~ using UnityEngine; using System.Collections; using UnityEngine.UI; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using UnityEngine.SocialPlatforms; using System.Xml.Serialization; using System.Xml; using System.Collections.Generic; public class PlayerController : MonoBehaviour {
// Use this for initialization
public GameObject me;
void Start () {
Load (); // Load Function Located under Save Function Under this
Time.timeScale = 1; // Resume on play
}
// Update is called once per frame
void Update () {
Save();
}
public void Save() {
// This is made for iOS and it wasn't working
// Along with .dat files, game.app/Documents/random.xml/, and .xml files
// Please help me!!!
if (!PlayerPrefs.HasKey ("x")) {
PlayerPrefs.SetFloat ("x", me.transform.position.x);
}
else {
PlayerPrefs.DeleteKey ("x");
PlayerPrefs.SetFloat ("x", me.transform.position.x);
}
if (!PlayerPrefs.HasKey ("y")) {
PlayerPrefs.SetFloat ("y", me.transform.position.y);
}
else {
PlayerPrefs.DeleteKey ("y");
PlayerPrefs.SetFloat ("y", me.transform.position.y);
}
if (!PlayerPrefs.HasKey ("z")) {
PlayerPrefs.SetFloat ("z", me.transform.position.z);
}
else {
PlayerPrefs.DeleteKey ("z");
PlayerPrefs.SetFloat ("z", me.transform.position.z);
}
PlayerPrefs.Save ();
}
public void Load() {
if (PlayerPrefs.HasKey("x") && PlayerPrefs.HasKey ("y") && PlayerPrefs.HasKey ("z")) {
float x = PlayerPrefs.GetFloat ("x");
float y = PlayerPrefs.GetFloat ("y");
float z = PlayerPrefs.GetFloat ("z");
me.transform.position = new Vector3(x, y, z);
}
else {
Save ();
Load ();
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613184821im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
is there a way to link .NET dll base on platform? 0 Answers
GPU Skinning on iOS Devices? 2 Answers
Occlusion Culling in IOS Build? 1 Answer
Error verifying Prime31Editor 0 Answers
Export IOS with windows (mobile) 3 Answers