Hello everybody.
I’m doing a battle system similar to FF XII. I have the main structure, but the problem has come when I’ve had to start with the GUI (you know, That little window in left-bottom border with Attack, Magick, Item, etc.)
Basically, I made a “noob” algorithm. I take Time.timeScale as flag.
If it is set to 0, we make some OnGUI functions, and the rest of the game freezes (the “static gui”).
If it is set to 1, we make other OnGUI functions (like timebar, hp bar, updates; that I call “dynamic gui”). Also we make normal actions, since time scale is set to 1.
For the static part:
I made three bools initialised at false. These are attack, item, magic. The code looks like this pseudo code:
OnGUI(){
if(Time.timeScale == 0) { //Static part (menu)
if(!attack !item !magic) {
if(Input.GetKeyDown(escape)) Time.timeScale = 1;
if(GUI.button("attack"..bla..bla)) attack = true;
if(GUI.button("item"...bla..bla)) item = true;
if(GUI.button("magic"..bla..bla)) magic = true;
} //This have been the main battle menu.
//Now we try to switch to other menus.
else if(attack) {
//If we wanna return to main menu
if(Input.GetKeyDown(escape)) attack = false;
StartCoroutine("end this frame function")
//The same menu with buttons but we add monsters...
}
else if...
//the same else's but with item and magic.
end brackets.
The problem comes when I’m in the attack menu, with monsters buttons. If I wanna go back to main menu pressing escape key, I would set attack back to false. I expected to see the main battle menu back, but the fact is that the time scale returned to 1. This only can be possible if OnGUI function is called again in the same frame, since the escape key will be considered as pressed down, and timeScale will be set up back to 1, in main battle block.
To solve this, I used a coroutine to end the frame, in order to ignore that espace key pressed down, but nothing happens.
Anyone has an idea to help me?
[/code]