Answer the question
In order to leave comments, you need to log in
How to make save in c#, unity3d?
public class Game : MonoBehaviour {
public int score;
public int bonus;
<i>public int[] costUpgrades;
public Text[] textUpgrades;</i>
private Save save = Save();
private string path;
void Awake ()
{
path = Path.Combine(Application.dataPath, "Save.json");
if (File.Exists (path)) {
save = JsonUtility.FromJson<Save> (File.ReadAllText (path));
score = save.score;
bonus = save.bonus;
}
void OnApplicationQuit ()
{
File.WriteAllText (path, JsonUtility.ToJson (save));
}
void Upgrade1 (int index)
{
if(score >= costUpgrades[index])
{
score -= costUpgrades[index];
...
}
}
void OnClick ()
{
score += bonus;
save.score = score;
}
}
[Serializable]
public class Save
{
public int bonus;
public int score;
public int[] costUpgrades;
public Text[] textUpgrades;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question