Exemplo n.º 1
0
    private void Update()
    {
        if (_exploded)
        {
            return;
        }

        machineSatiation -= _satiationDegradationRate * Time.deltaTime;
        _uiManager.UpdateNeedle(machineSatiation);

        if (machineSatiation < DANGER_ZONE_BELOW && !_warningGiven)
        {
            _uiManager.ShowMessage("The machine is in danger of exploding!");
            _warningGiven = true;
        }
        else if (machineSatiation > SLEEP_ZONE_ABOVE && !_warningGiven)
        {
            _uiManager.ShowMessage("The machine may go to sleep");
            _warningGiven = true;
        }
        else if (machineSatiation >= DANGER_ZONE_BELOW && machineSatiation <= SLEEP_ZONE_ABOVE)
        {
            // clear the warning flag so that future warnings can be given
            _warningGiven = false;
        }

        if (_currentDemand == null)
        {
            timeTillNextDemand -= Time.deltaTime;
            if (timeTillNextDemand <= 0)
            {
                _currentDemand = Demand.GenerateDemand();
                _uiManager.SetMachineDemandText(_currentDemand.ToString());
                timeTillNextDemand = Random.Range(MIN_DEMAND_DELAY, MAX_DEMAND_DELAY);
            }
        }
    }