// Start is called before the first frame update void Start() { //WindowManager.instance.ScreenSizeChangeEvent += Instance_ScreenSizeChangeEvent; DetectPossibleMoves.SetBooleans(); GamePieces.FindGameBlocks(); GamePieces.FindGamePieces(); clickAndDropScript = gameObject.GetComponent <ClickAndDrop>(); gameOverCanvas = GameObject.FindGameObjectWithTag("GameOverCanvas"); restartButton = GameObject.FindGameObjectWithTag("RestartButton"); changeColorButton = GameObject.FindGameObjectWithTag("ChangeColor"); highScoreIcon = GameObject.FindGameObjectWithTag("HighScoreIcon"); background = GameObject.FindGameObjectWithTag("BlurBG"); gameOverCanvas.SetActive(false); restartButton.SetActive(false); changeColorButton.SetActive(true); background.SetActive(false); highScoreIcon.SetActive(true); // Change BG var camera = (Camera)FindObjectOfType(typeof(Camera)); camera.backgroundColor = SetColor.GetColor("Background"); // Change Grid AnimateGrid.SetGrid(); UpdateColor(); }
void UpdateColor() { // Change BG var camera = (Camera)FindObjectOfType(typeof(Camera)); camera.backgroundColor = SetColor.GetColor("Background"); // Change Grid AnimateGrid.SetGrid(); // Change Icon Color on highscore SpriteRenderer HighScoreIconRender = highScoreIcon.GetComponent <SpriteRenderer>(); if (SetColor.GetDarkMode() == true) { HighScoreIconRender.color = SetColor.GetColor("Font"); } else { HighScoreIconRender.color = SetColor.GetColor("Font"); } // Change ChangeIconImage Image Image changeColorButtonImage = changeColorButton.GetComponent <Image>(); //Debug.Log(changeColorButtonImage); if (SetColor.GetDarkMode() == true) { changeColorButtonImage.sprite = Resources.Load <Sprite>("Images/GridIconAlt"); } else { changeColorButtonImage.sprite = Resources.Load <Sprite>("Images/GridIconDark"); } // Change Labels GameObject[] labels = GameObject.FindGameObjectsWithTag("TextLabel"); foreach (var a in labels) { MeshRenderer bgBlock = a.GetComponent <MeshRenderer>(); Material[] meshMats = bgBlock.materials; if (SetColor.GetDarkMode() == true) { meshMats[0] = null; meshMats[0] = SetColor.GetMaterial("Grid"); } else { meshMats[0] = null; meshMats[0] = SetColor.GetMaterial("Grid"); } bgBlock.materials = meshMats; } // Changel Text on Labels GameObject[] textLabels = GameObject.FindGameObjectsWithTag("ScoreText"); // Set UI Text to objects to access //Debug.Log(objs.Length); foreach (var i in textLabels) { var t = i.GetComponent <Text>(); if (t.name.Equals("HighScore")) { if (SetColor.GetDarkMode() == true) { t.color = SetColor.GetColor("Font"); } else { t.color = SetColor.GetColor("Font"); } } if (t.name.Equals("CurrentScore")) { if (SetColor.GetDarkMode() == true) { t.color = SetColor.GetColor("Font"); } else { t.color = SetColor.GetColor("Font"); } } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonUp(0) || Input.GetMouseButton(0)) { _canUpdateColor = true; _canUpdateGrid = true; _gatherColorTime = 0f; } // Set the color of the grid if (AnimateGrid.setGrid == false && _updateOnce == true) { //_gatherGridTime += Time.deltaTime; //if (_gatherGridTime > _waitTime) //_canUpdateGrid = false; AnimateGrid.SetGrid(); AnimateGrid.setGrid = true; // Changel Text on Labels GameObject[] textLabels = GameObject.FindGameObjectsWithTag("ScoreText"); // Set UI Text to objects to access //Debug.Log(objs.Length); foreach (var i in textLabels) { var t = i.GetComponent <Text>(); if (t.name.Equals("HighScore")) { if (SetColor.GetDarkMode() == true) { t.color = SetColor.GetColor("Font"); } else { t.color = SetColor.GetColor("Font"); } } if (t.name.Equals("CurrentScore")) { if (SetColor.GetDarkMode() == true) { t.color = SetColor.GetColor("Font"); } else { t.color = SetColor.GetColor("Font"); } } } _updateOnce = false; } // Change colors to Light / Dark mode if (SetColor.WillChangeColor == true && _canUpdateColor == true) { _gatherColorTime += Time.deltaTime; if (_gatherColorTime > _waitTime) { _canUpdateColor = false; } UpdateColor(); SetColor.WillChangeColor = false; } // Restart game if (GameOverInfo.RestartGame == true) { gameOverCanvas.SetActive(false); restartButton.SetActive(false); background.SetActive(false); GameOverInfo.RestartGame = false; AnimateGrid.setGrid = false; SetColor.WillChangeColor = true; _updateOnce = true; SceneManager.LoadScene(SceneManager.GetActiveScene().name); } // Check if Game Over if (DetectPossibleMoves.IsGameOver == true) { if (triggerOnce == true) { GameOver(); //Debug.Log("Game Over"); triggerOnce = false; } } else { if (!checkedAvaliablePieces || DetectPossibleMoves.DidNewBlocksSpawn) { DetectPossibleMoves.SetBooleans(); DetectPossibleMoves.AnalyzeGrid(); DetectPossibleMoves.IsThereAValidMove(); checkedAvaliablePieces = true; GamePieces.HasAnGamePieceBeenPlayedToUpdateScore = true; } // Logic for the grid GamePieces.FindGameBlocks(); GamePieces.FindGamePieces(); GamePieces.WhereAreGamePiecesToPlay(); AnimateGrid.FindBackgroundBlocks(); /* If the left (main) mouse click is released * remove cleared blocks */ if (Input.GetMouseButtonUp(0) || isMouseReleased) { if (GamePieces.isAPlayValid) { GameGrid.UpdatePlayedPiecesOnGrid(this); } UpdateGameLogic(); getRefresh = true; isMouseReleased = false; UpdateAnimation(); } if (GamePieces.isAPlayValid) { if (GamePieces.isAPlayValid) { GameGrid.UpdatePlayedPiecesOnGrid(this); } checkedAvaliablePieces = false; } } }