I'm gonna add a pause menu later and whenever you go back the main menu with that it will save your high score there too.
25 lines
826 B
C#
25 lines
826 B
C#
using Godot;
|
|
|
|
public partial class BazookaManager : Node {
|
|
public static string HighScore = "0";
|
|
|
|
public static string Read(string saveKey, string defaultValue) {
|
|
string path = "user://" + saveKey + ".txt";
|
|
if (!FileAccess.FileExists(path)) {
|
|
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
|
|
file.StoreString(defaultValue);
|
|
return defaultValue;
|
|
} else {
|
|
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
|
|
return file.GetAsText();
|
|
}
|
|
}
|
|
|
|
public static void Write(string saveKey, string value) {
|
|
string path = "user://" + saveKey + ".txt";
|
|
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
|
|
file.StoreString(value);
|
|
file.Flush();
|
|
}
|
|
}
|