Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- public class UpdateColor : MonoBehaviour
- {
- [SerializeField] private Image cookie;
- [SerializeField] private Color[] colors;
- [SerializeField] private TextMeshProUGUI scoreText;
- private void Update()
- {
- var score = int.Parse(scoreText.text.ToString());
- if(score > 10 && score < 50)
- {
- scoreText.color = colors[GenerateRandomIndex()];
- }
- else if (score > 50 && score < 100)
- {
- scoreText.color = colors[GenerateRandomIndex()];
- }
- else if (score > 100 && score < 200)
- {
- scoreText.color = colors[GenerateRandomIndex()];
- }
- else if (score > 200)
- {
- scoreText.color = colors[GenerateRandomIndex()];
- }
- }
- public void SetupColor()
- {
- cookie.color = colors[GenerateRandomIndex()];
- }
- private int GenerateRandomIndex()
- {
- return Random.Range(0, colors.Length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment