-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveLoad.cs
102 lines (84 loc) · 2.55 KB
/
SaveLoad.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using UnityEngine;
using System.Collections;
public class SaveLoad : MonoBehaviour
{
public static bool newGame = true;
public static bool saveOrLoad = false;
public GameObject fadeScreen;
bool save = false;
bool load = false;
bool[] haveData = new bool[10];
string slotX;
public GUISkin personalizedSkin;
Player playerScript;
// Use this for initialization
void Start () {
playerScript = GameObject.Find ("/Hercules").GetComponent<Player>();
fadeScreen = GameObject.Find ("/Canvas/Fade Screen");
fadeScreen.SetActive (false);
}
// Update is called once per frame
void Update () {
}
void SaveLoadNewGame (int num) {
if (num == 0) {
save = true;
load = false;
}
if (num == 1) {
load = true;
save = false;
}
}
void OnGUI () {
GUI.skin = personalizedSkin;
if (saveOrLoad == true) {
if (GUI.Button (new Rect(Screen.width - 170, Screen.height - 40, 160, 30), "Return")) {
Menu.backButtonWasPressed = true;
}
for (int i = 0; i < 10; i++) {
if (GUI.Button (new Rect(0, Screen.height/2 - Screen.height/4 - 25 + (i * 35), Screen.width,35), "Slot "+(i+1))) {
if (save == true) {
SlotN (i);
Save (i);
save = false;
playerScript.Pause (true);
saveOrLoad = false;
}
if (load == true) {
SlotN (i);
Load (i);
load = false;
}
}
if (GUI.Button (new Rect(0, Screen.height/2 - Screen.height/4 - 25 + (i * 35), Screen.width, 35), "Slot "+(i+1))) {
}
}
}
}
void Save (int num) {
if (haveData[num] == false) {
PlayerPrefs.SetInt(slotX+"CurrentLevel", Menu.numLevel);
PlayerPrefs.SetInt(slotX+"Life", playerScript.life);
PlayerPrefs.SetFloat(slotX+"PositionPlayerX", playerScript.positionPlayer.x);
PlayerPrefs.SetFloat(slotX+"PositionPlayerY", playerScript.positionPlayer.y);
PlayerPrefs.SetFloat(slotX+"PositionPlayerZ", playerScript.positionPlayer.z);
haveData[num] = true;
}
}
void Load (int num) {
if (haveData[num] == true) {
Menu.numLevel = PlayerPrefs.GetInt(slotX+"CurrentLevel");
playerScript.life = PlayerPrefs.GetInt(slotX+"Life");
playerScript.positionPlayer.x = PlayerPrefs.GetFloat(slotX+"PositionPlayerX");
playerScript.positionPlayer.y = PlayerPrefs.GetFloat(slotX+"PositionPlayerY");
playerScript.positionPlayer.z = PlayerPrefs.GetFloat(slotX+"PositionPlayerZ");
fadeScreen.SetActive (true);
Application.LoadLevel ("Job"+(Menu.numLevel));
}
}
void SlotN (int slot) {
slotX = "Slot"+slot;
print ("Num Slot: "+slot+" --- Name Slot: "+slotX);
}
}