I have two coroutines, one for Loading and another for Saving, both corutines are pretty much the same, in fact I copies and pasted one to create another, yet one of them does stuff without meeting the conditions (in this case, pressing the “attack” button), the loading coroutine just loads the first save slot without me ever pressing the attack button.
I cant post the whole code as is quite large but here are the coroutines
IEnumerator LoadCo(){
GameObject GameManager = GameObject.FindGameObjectWithTag("GameManager");
SaveSystem _SaveSystem = GameManager.GetComponent<SaveSystem>();
if (Input.GetButtonDown("attack1") == true){
audio.PlayOneShot(SelectMenu);
_SaveSystem.Load(MenuString);
yield return new WaitForSeconds(1);
}
}
IEnumerator SaveCo(){
GameObject GameManager = GameObject.FindGameObjectWithTag("GameManager");
SaveSystem _SaveSystem = GameManager.GetComponent<SaveSystem>();
if (Input.GetButtonDown("attack1") == true){
audio.PlayOneShot(SelectMenu);
_SaveSystem.Save(MenuString);
yield return new WaitForSeconds(1);
}
}
And a switch I have, this is all the relevant code as the rest is OnGUI stuff.
switch(MenuIndex){
case -1:
MenuIndex = 3;
break;
case 0:
if (PauseMenuInt == 0){
MenuString = "Resume";
if (Input.GetButtonDown("attack1") == true){
audio.PlayOneShot(SelectMenu);
_GameManager.MenuBool = false;
}
}
if (PauseMenuInt == 1){
MenuString = "Slot 1";
StartCoroutine (SaveCo());
}
if (PauseMenuInt == 2){
MenuString = "Slot 1";
StartCoroutine (LoadCo());
}
break;
case 1:
if (PauseMenuInt == 0){
MenuString = "Save";
if (Input.GetButtonDown("attack1") == true){
audio.PlayOneShot(SelectMenu);
PauseMenuInt = 1;
}
}
if (PauseMenuInt == 1){
MenuString = "Slot 2";
StartCoroutine (SaveCo());
}
if (PauseMenuInt == 2){
MenuString = "Slot 2";
StartCoroutine (LoadCo());
}
break;
case 2:
if (PauseMenuInt == 0){
MenuString = "Load";
if (Input.GetButtonDown("attack1") == true){
audio.PlayOneShot(SelectMenu);
PauseMenuInt = 2;
}
}
if (PauseMenuInt == 1){
MenuString = "Slot 3";
StartCoroutine (SaveCo());
}
if (PauseMenuInt == 2){
MenuString = "Slot 3";
StartCoroutine (LoadCo());
}
break;
case 3:
if (PauseMenuInt == 0){
MenuString = "Exit";
if (Input.GetButtonDown("attack1") == true){
audio.PlayOneShot(SelectMenu);
Application.Quit();
}
}
if (PauseMenuInt == 1){
MenuString = "Back";
if (Input.GetButtonDown("attack1") == true){
audio.PlayOneShot(SelectMenu);
PauseMenuInt = 0;
}
}
break;
case 4:
MenuIndex = 0;
break;
}
if (Input.GetButtonDown("Digipad_down") == true){
audio.PlayOneShot(MenuFocus);
MenuIndex += 1;
}
if (Input.GetButtonDown("Digipad_up") == true){
audio.PlayOneShot(MenuFocus);
MenuIndex -= 1;
}
I dont know whats wrong, please help me.