Survival 2D game. Problem with the script

Hello, I recently started learning Unity and decided to create a Survival game in 2D.

I tried to write a script for temperature, satiety level, intoxication level, etc. but when I try to launch the game, the engine either crashes or takes forever to load.

What am I doing wrong?

I wanted to achieve the effect that after some time, the player would get cold, hungry, thirsty and so on.

using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;

public class PlayerNeeds : MonoBehaviour
{
    [SerializeField] int temperatureSlowSpeed = 240000;
    [SerializeField] int eatSlowSpeed = 180000;
    [SerializeField] int waterSlowSpeed = 150000;
    [SerializeField] int energySlowSpeed = 300000;
    int eatLevel;
    int waterLevel;
    int energy;
    int temperatureLevel;
    bool temperature;

    void Awake()
    {
        eatLevel = 10;
        waterLevel = 10;
        energy = 100;
        temperatureLevel = 10;
        temperature = true;
    }

    void FixedUpdate()
    {

        if (waterLevel >= 8)
        {
            Thread.Sleep((int)120000);
            temperatureSlowSpeed += 20000;
            eatSlowSpeed += 20000;
            energySlowSpeed += 20000;
        }

        if (waterLevel <= 4)
        {
            Thread.Sleep((int)140000);
            temperatureSlowSpeed -= 30000;
            energySlowSpeed -= 30000;
        }

        if (eatLevel >= 8)
        {
            Thread.Sleep((int)120000);
            temperatureSlowSpeed += 20000;
            waterSlowSpeed += 20000;
            energySlowSpeed += 20000;
        }

        if (eatLevel <= 4)
        {
            Thread.Sleep((int)140000);
            temperatureSlowSpeed -= 30000;
            waterSlowSpeed -= 30000;
            energySlowSpeed -= 30000;
        }

        if (energy <= 10)
        {
            Thread.Sleep((int)100000);
            temperatureSlowSpeed -= 20000;
            energySlowSpeed -= 20000;
            waterSlowSpeed -= 20000;
        }

        if (temperatureLevel <= 4)
        {
            temperature = false;
        }

        if (temperatureLevel == 0)
        {
            Thread.Sleep((int)30000);
            Death();
        }
        if (waterLevel == 0)
        {
            Thread.Sleep((int)30000);
            Death();
        }
        if (eatLevel == 0)
        {
            Thread.Sleep((int)30000);
            Death();
        }

        if (temperature == false)
        {
            Freezing();
        }
    }

    void Update()
    {
        if (temperatureSlowSpeed >= 300000)
        {
            temperatureSlowSpeed = 300000;
        }
        if (eatLevel >= 10)
        {
            eatLevel = 10;
        }
        if (waterLevel >= 10)
        {
            waterLevel = 10;
        }
        if (energy >= 10)
        {
            energy = 10;
        }
        if (temperatureLevel >= 10)
        {
            temperatureLevel = 10;
        }

        TemperatureF();
        EatF();
        WaterF();
        EnergyF();
    }

    void Death()
    {
        Debug.Log("Kaput");
    }

    void Freezing()
    {
        Thread.Sleep((int)60000);
        temperatureLevel--;
    }

    void TemperatureF()
    {
        Thread.Sleep((int)temperatureSlowSpeed);
        temperatureLevel--;
    }

    void EatF()
    {
        Thread.Sleep((int)eatSlowSpeed);
        eatLevel--;
    }

    void WaterF()
    {
        Thread.Sleep(waterSlowSpeed);
        waterLevel--;
    }

    void EnergyF()
    {
        Thread.Sleep(energySlowSpeed);
        energy--;
    }
}

Thread.Sleep() means “please make the entire engine hang for this long”. So that’s what’s doing it.

There’s better ways of achieving the same thing - the most straightforwards is to have a counter in the class that’s “how long until I lose eg. energy”, subtract Time.deltaTime from that each frame, and when it’s under 0 subtract 1 energy and reset the variable to the starting value to start over again.

Edited: @Baste explained it clearly while I was writing a response :muscle: