- Home /
Question by
FlippingFlopper · Nov 28, 2018 at 12:21 PM ·
update functionprocess
A proper way to manage game process?????
Hi. I am currently making a game which has countdown for game progress. I take care of game process in Update function, just as below. But it guess there must be some better ways to do this. is there proper ways to manage this ??? if there is, what is the keyword that I have to search on google to learn it. Thanks you all.
void Update () {
if (gameStatus == "Waiting") {
// do the stuff for waiting situation.
if(conditionForNextProcess) {
gameStatus = "Countdown";
}
} else if (gameStatus == "Countdown") {
//do things for countdown situation.
if (conditionForNextProcess2) {
gameStatus = "Playing";
}
} else if (gameStatus == "Playing") {
//do things for Playing situation.
if (conditionForNextProcess3) {
gameStatus = "GameOver";
}
}
}
Comment
@FlippingFlopper - search for State $$anonymous$$achine or Finite State $$anonymous$$achine
Answer by HenBOMB · Nov 28, 2018 at 11:35 PM
You can use an enumerator:
public enum GS{
Waiting, Coutdown, GameOver, Playing
}
public GS GameStatus;
public int health;
public bool startCountdown;
public bool timeIsUp;
void Update () {
if (gameStatus == GS.Waiting) {
}
if(startCountdown) {
gameStatus = GS.Countdown;
}
else if (gameStatus == GS.CountDown) {
if (timeIsUp) {
gameStatus = GS.Playing;
}
}
else if (gameStatus == GS.Playing) {
}
if (health <= 0) {
gameStatus = GS.GameOver;
}
}