```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;

// note for self, nekad vairāk nerakstit 400 liniju script, ja tas nav needed.

// !TODO add color changing after each level.
// !TODO fix level text not updating

public class TetrisBlock : MonoBehaviour
{
    public static byte LinesCleared;
    public static int height = 21;
    public static int width = 10;
    public static float fallTimeDecrease;
    public static float minFallTime = 0.1f;
    public static float fallTime;
    public static float CurrentFallTime { get; private set; } = 1f;
    public static byte linesPerLevel = 10;
    public static bool gameOver = false;

    private float initialFallTime = 1f;
    private float previousTime;
    private static int level = 0;

    private GameManager gameManager;
    private SpawnTetromino spawnTetromino;
    private static TextMeshProUGUI linesClearedText;
    private static TextMeshProUGUI LevelText;
    private AudioSource audioSource;
    public Vector3 rotationPoint;
    
    private static TetrisBlock instance;
    
    private static Color[] levelColors = new Color[]
    {
        Color.cyan,
        Color.yellow,
        Color.magenta,
        Color.red,
        Color.green,
        Color.blue,
        Color.white
    };

    public AudioClip moveSound;

    void Awake()
    {
        gameManager = FindObjectOfType<GameManager>();
        spawnTetromino = FindObjectOfType<SpawnTetromino>();
        linesClearedText = GameObject.Find("Lines_Cleared").GetComponent<TextMeshProUGUI>();
        LevelText = GameObject.Find("Level_Text").GetComponent<TextMeshProUGUI>();
        fallTime = CurrentFallTime;
        
        if (LevelText = null)
        {
            Debug.LogError("No level text found");
        }
        
        Debug.Log(SceneController.noFunPressed);

        ResetGame();
        SetupAudioSource();
        UpdateBlockColor();
        CalculateFallDecrement();

        instance = this;
        moveSound = AudioManager.Instance.audioClips[0];
        
    }

    private void Update()
    {
        if (gameManager.StartMenu != null && !gameManager.StartMenu.activeSelf)
        {
            HandleInput();
        }
    }

    void CalculateFallDecrement()
    {
        if (SceneController.noFunPressed)
        {
            fallTimeDecrease = 0.9f;
        } 
        else if (SceneController.sweatPressed)
        {
            fallTimeDecrease = 0.4f;
        }
        else if (SceneController.hardPressed)
        {
            fallTimeDecrease = 0.2f;
        }
        else if (SceneController.SkillIssuePressed)
        {
            fallTimeDecrease = 0.05f;
        }
        else
        {
            fallTimeDecrease = 0.1f;
        }
    }

    private void ResetGame()
    {
        if (SceneController.hasRestartedScene)
        {
            gameManager.StartMenu.SetActive(false);
            CurrentFallTime = initialFallTime;
            level = 0;
            LinesCleared = 0;
            UpdateUi();
            SceneController.hasRestartedScene = false;
            Debug.Log($"The current fall time is: {CurrentFallTime}");
        }
    }

    private void HandleInput()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
        {
            MoveHorizontal(-1);
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
        {
            MoveHorizontal(1);
        }
        else if (Input.GetKeyDown(KeyCode.X))
        {
            Rotate();
        }
        if (Time.time - previousTime > (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S) ? fallTime / 10 : fallTime))
        {
            MoveDown();
        }
    }

    private void MoveHorizontal(int direction)
    {
        AudioManager.Instance.PlayMoveSound();
        transform.position += new Vector3(direction, 0, 0);
        if (!ClearLine.ValidMove(transform))
            transform.position -= new Vector3(direction, 0, 0);
    }

    private void Rotate()
    {
        transform.RotateAround(transform.TransformPoint(rotationPoint), Vector3.forward, 90);
        if (!ClearLine.ValidMove(transform))
            transform.RotateAround(transform.TransformPoint(rotationPoint), Vector3.forward, -90);
    }

    private void MoveDown()
    {
        transform.position += Vector3.down;
        if (!ClearLine.ValidMove(transform))
        {
            transform.position -= Vector3.down;
            ClearLine.AddToGrid(transform);
            ClearLine.CheckForLines();
            this.enabled = false;

            if (!ClearLine.isLineClearAnimationInProgress && !gameOver)
            {
                spawnTetromino.NewTetromino();
            }
        }
        previousTime = Time.time;
    }

    public static void UpdateUi()
    {
        if (linesClearedText != null)
        {
            linesClearedText.text = "Lines Cleared: " + LinesCleared.ToString();
        }
        if (LevelText != null)
        {
            LevelText.text = "Level: " + level.ToString();
        }
        else
        {
            Debug.LogError("Lines_Cleared TextMeshProUGUI component not found!");
        }
    }
    
    public static void LevelUp()
    {
        int newLevel = LinesCleared / linesPerLevel;
        
        if (newLevel > level)
        {
            int levelDifference = newLevel - level;
            for (int i = 0; i < levelDifference; i++)
            {
                CurrentFallTime = Mathf.Max(CurrentFallTime - fallTimeDecrease, minFallTime);
            }
            
            UpdateBlockColor();
            level = newLevel;
            
            // !TODO Maybe if there is time make the achivement be saved and displayed in start menu.
            if (newLevel == 157)
            {
                GameManager.Instance.WaitWhat();
            }
        }
        Debug.Log(CurrentFallTime);
        Debug.Log(level);
    }

    public static void ResetStaticVariables()
    {
        ClearLine.ResetGrid();
        LinesCleared = 0;
        gameOver = false;
    }

    private void PlayMoveSound()
    {
        if (audioSource != null && moveSound != null)
        {
            audioSource.PlayOneShot(moveSound);
        }
    }

    private void SetupAudioSource()
    {
        if (audioSource == null)
        {
            audioSource = gameObject.AddComponent<AudioSource>();
        }

        audioSource.clip = moveSound;
        audioSource.playOnAwake = false;
    }
    
    private static void UpdateBlockColor()
    {
        Color newColor = levelColors[level % levelColors.Length];
        foreach (Transform child in FindObjectOfType<SpawnTetromino>().transform)
        {
            foreach (Transform grandchild in child)
            {
                Renderer renderer = grandchild.GetComponent<Renderer>();
                if (renderer != null)
                {
                    renderer.material.color = newColor;
                }
            }
        }
    }
}

```
fix the issue where the color doesn't change