// Use this for initialization void Start() { Screen.orientation = ScreenOrientation.LandscapeLeft; _timer = 0.0f; Screen.sleepTimeout = SleepTimeout.NeverSleep; Gameoptions.Start(); _countList = new int [6]; _lockTimer = 0; _gameStateTimer = 0; _gameState = EDU_GAMESTATES.STARTUP; _stateStart = true; _correctBurstTimer = 0; }
void UpdateEduGameLogic() { _gameStateTimer += Time.deltaTime; switch (_gameState) { case EDU_GAMESTATES.STARTUP: _gameStateTimer = 0; _gameState = EDU_GAMESTATES.PROMPT; _stateStart = true; break; case EDU_GAMESTATES.PROMPT: //Audio for Color guess CUE// if (_gameStateTimer > 3.0) { _gameStateTimer = 0; _gameState = EDU_GAMESTATES.DISPLAY; _stateStart = true; } break; case EDU_GAMESTATES.DISPLAY: if (_stateStart) { Firework script1 = (Firework)fireWork.GetComponent("Firework"); script1.color = GetColor(); _gameStateTimer = 0; _stateStart = false; Vector3 pos1 = new Vector3(Random.Range(0, 45) / 5 - 4, Random.Range(0, 30) / 5 - 1, 0); Instantiate(fireWork, pos1, Quaternion.identity); } else if (_gameStateTimer >= _burstRandomTimer) { _gameStateTimer = 0; Firework script1 = (Firework)fireWork.GetComponent("Firework"); script1.color = GetColor(_color); Vector3 pos1 = new Vector3(Random.Range(0, 45) / 5 - 4, Random.Range(0, 30) / 5 - 1, 0); Instantiate(fireWork, pos1, Quaternion.identity); SetRandomTimer(0.5f); if (Random.Range(1, 3) == 1) { _gameState = EDU_GAMESTATES.WAIT; _stateStart = true; } } break; case EDU_GAMESTATES.WAIT: if (_gameStateTimer > _burstRandomTimer) { Firework script = (Firework)fireWork.GetComponent("Firework"); script.color = GetColor(_color); Vector3 pos = new Vector3(Random.Range(0, 45) / 5 - 4, Random.Range(0, 30) / 5 - 1, 0); Instantiate(fireWork, pos, Quaternion.identity); _gameStateTimer = 0; SetRandomTimer(2.5f); } break; case EDU_GAMESTATES.CORRECT: //audio correct prompt play// if (_stateStart) { _correctBurstTimer = 0; SetRandomTimer(0.70f); _stateStart = false; } _correctBurstTimer += Time.deltaTime; if (_correctBurstTimer >= _burstRandomTimer) { Firework script2 = (Firework)fireWork.GetComponent("Firework"); script2.color = GetColor(); Vector3 pos2 = new Vector3(Random.Range(0, 45) / 5 - 4, Random.Range(0, 30) / 5 - 1, 0); Instantiate(fireWork, pos2, Quaternion.identity); _correctBurstTimer = 0; SetRandomTimer(0.70f); } if (_gameStateTimer > 3.0) { _gameState = EDU_GAMESTATES.CLEANUP; } break; case EDU_GAMESTATES.INCORRECT: //audio incorrect prompt play// if (_gameStateTimer > 3.0) { _gameState = EDU_GAMESTATES.WAIT; } break; case EDU_GAMESTATES.CLEANUP: _gameState = EDU_GAMESTATES.STARTUP; break; } }
void OnGUI() { GUIScale.SetGuiMatrix(); GUI.skin.label.fontSize = 72; GUI.skin.button.fontSize = 48; GUI.skin.box.fontSize = 36; if (Gameoptions.TypeGame == 1) { for (int i = 0; i < Gameoptions.NumColors; i++) { if (_gameState != EDU_GAMESTATES.WAIT) { GUI.enabled = false; } if (GUI.Button(new Rect((GUIScale.virtualWidth / Gameoptions.NumColors) * i, GUIScale.virtualHeight * 0.85f, (GUIScale.virtualWidth / Gameoptions.NumColors), GUIScale.virtualHeight * 0.15f), GetColorString(i)) && _gameState == EDU_GAMESTATES.WAIT) { if (_color == i) { _gameState = EDU_GAMESTATES.CORRECT; _gameStateTimer = 0; _stateStart = true; } else { _gameState = EDU_GAMESTATES.INCORRECT; _gameStateTimer = 0; _stateStart = true; } } } GUI.enabled = true; if (_gameState == EDU_GAMESTATES.PROMPT) { GUI.skin.box.fontSize = 72; GUI.Box(new Rect(GUIScale.virtualWidth * 0.2f, GUIScale.virtualHeight * 0.3f, GUIScale.virtualWidth * 0.6f, 86), "Guess the Color!"); } else if (_gameState == EDU_GAMESTATES.CORRECT) { GUI.skin.box.fontSize = 72; GUI.Box(new Rect(GUIScale.virtualWidth * 0.2f, GUIScale.virtualHeight * 0.3f, GUIScale.virtualWidth * 0.6f, 86), "Thats Right!"); } else if (_gameState == EDU_GAMESTATES.INCORRECT) { GUI.skin.box.fontSize = 72; GUI.Box(new Rect(GUIScale.virtualWidth * 0.2f, GUIScale.virtualHeight * 0.3f, GUIScale.virtualWidth * 0.6f, 86), "Not Quite! Guess again!"); } } if (Gameoptions.TypeGame == 3) { for (int i = 0; i < _countList.Length; i++) { if (_gameState != EDU_GAMESTATES.WAIT) { GUI.enabled = false; } if (GUI.Button(new Rect((GUIScale.virtualWidth / _countList.Length) * i, GUIScale.virtualHeight * 0.85f, (GUIScale.virtualWidth / _countList.Length), GUIScale.virtualHeight * 0.15f), GetArrayString(i)) && _gameState == EDU_GAMESTATES.WAIT) { if (_countList[i] == countTarget) { _gameState = EDU_GAMESTATES.CORRECT; _gameStateTimer = 0; _stateStart = true; } else { _gameState = EDU_GAMESTATES.INCORRECT; _gameStateTimer = 0; _stateStart = true; } } } GUI.enabled = true; if (_gameState == EDU_GAMESTATES.PROMPT) { GUI.skin.box.fontSize = 72; GUI.Box(new Rect(GUIScale.virtualWidth * 0.2f, GUIScale.virtualHeight * 0.3f, GUIScale.virtualWidth * 0.6f, 86), "Count the Fireworks!"); } else if (_gameState == EDU_GAMESTATES.CORRECT) { GUI.skin.box.fontSize = 72; GUI.Box(new Rect(GUIScale.virtualWidth * 0.2f, GUIScale.virtualHeight * 0.3f, GUIScale.virtualWidth * 0.6f, 86), "Thats Right!"); } else if (_gameState == EDU_GAMESTATES.INCORRECT) { GUI.skin.box.fontSize = 72; GUI.Box(new Rect(GUIScale.virtualWidth * 0.2f, GUIScale.virtualHeight * 0.3f, GUIScale.virtualWidth * 0.6f, 86), "Not Quite!"); } } }
//Having two game type updates is totally unnecesary, but I wrote the original code so long ago //I forget how it works to modify it for counting game. void UpdateCountGameLogic() { _gameStateTimer += Time.deltaTime; switch (_gameState) { case EDU_GAMESTATES.STARTUP: _gameStateTimer = 0; _gameState = EDU_GAMESTATES.PROMPT; _stateStart = true; break; case EDU_GAMESTATES.PROMPT: //Audio for Color guess CUE// if (_gameStateTimer > 3.0) { _gameStateTimer = 0; _gameState = EDU_GAMESTATES.DISPLAY; _stateStart = true; } break; case EDU_GAMESTATES.DISPLAY: if (_stateStart) { //Firework script1 = (Firework)fireWork.GetComponent("Firework"); //script1.color = GetColor(); _gameStateTimer = 3.0f; countCurrent = 0; _stateStart = false; countTarget = Random.Range(1, 9); } if (_gameStateTimer > 2.5) { Firework script1 = (Firework)fireWork.GetComponent("Firework"); script1.color = GetColor(); Vector3 pos1 = new Vector3(Random.Range(0, 45) / 5 - 4, Random.Range(0, 30) / 5 - 1, 0); Instantiate(fireWork, pos1, Quaternion.identity); countCurrent++; _gameStateTimer = Random.Range(0, 1.0f); } if (countCurrent == countTarget) { _gameState = EDU_GAMESTATES.WAIT; _stateStart = true; GenerateCountList(); } break; case EDU_GAMESTATES.WAIT: break; //If no correct state set to startup// case EDU_GAMESTATES.CORRECT: //audio correct prompt play// a_audio.Correct(); if (_stateStart) { _correctBurstTimer = 0; SetRandomTimer(0.70f); _stateStart = false; } _correctBurstTimer += Time.deltaTime; if (_correctBurstTimer >= _burstRandomTimer) { Firework script2 = (Firework)fireWork.GetComponent("Firework"); script2.color = GetColor(); Vector3 pos2 = new Vector3(Random.Range(0, 45) / 5 - 4, Random.Range(0, 30) / 5 - 1, 0); Instantiate(fireWork, pos2, Quaternion.identity); _correctBurstTimer = 0; SetRandomTimer(0.70f); } if (_gameStateTimer > 3.0) { _gameState = EDU_GAMESTATES.CLEANUP; } break; case EDU_GAMESTATES.INCORRECT: //audio incorrect prompt play// if (_gameStateTimer > 3.0) { _gameState = EDU_GAMESTATES.CLEANUP; } break; case EDU_GAMESTATES.CLEANUP: _gameState = EDU_GAMESTATES.STARTUP; break; default: _gameState = EDU_GAMESTATES.STARTUP; break; } ; }