public void InitializeGame(string selectedBoardSize) { // Reset game data LoopScript[] existingLoops = FindObjectsOfType <LoopScript>(); foreach (LoopScript loop in existingLoops) { Destroy(loop.gameObject); } GameObject[] existingDiamonds = GameObject.FindGameObjectsWithTag("Diamond"); foreach (GameObject diamond in existingDiamonds) { Destroy(diamond); } foreach (Image strike in strikes) { strike.color = Color.white; } gameOverScreen.SetActive(false); difficultySelectionScreen.SetActive(false); speedModifier = 1f; diamondCount = 0; strikeCount = 0; isGameOver = false; diamondLocationX = 0; diamondLocationY = 0; diamondText.text = "0"; player.coolDown = 0f; // Initialize board boardSize = int.Parse(selectedBoardSize); int halfSize = Mathf.FloorToInt(boardSize * 0.5f); for (int x = -halfSize; x <= halfSize; x++) { for (int y = -halfSize; y <= halfSize; y++) { LoopScript newLoop = Instantiate(loopObject, new Vector2(x, y), Quaternion.identity) .GetComponent <LoopScript>(); if ((Mathf.Abs(x) == halfSize && Mathf.Abs(y) == halfSize) || (x == 0 && y == 0)) { newLoop.isStable = true; } newLoop.Initialize(); } } CreateDiamondAtNewLocation(); }
private void Start() { SourceJump = GetComponent <AudioSource>(); ObjectHC = GameObject.Find("LoopBGM"); ControllerHC = ObjectHC.GetComponent <LoopScript>(); }