コード例 #1
0
        private void Update()
        {
            // Day.
            var formattedDay = Mathf.Ceil(timeCycle.GetTime() / timeCycle.GetDayLength());

            dayText.text = $"Day: {formattedDay}";
            // Time.
            var currentTime   = timeCycle.GetTime() % timeCycle.GetDayLength() / timeCycle.GetDayLength() * 24;
            var currentHour   = Mathf.Floor(currentTime);
            var currentMinute = Mathf.Floor((currentTime - currentHour) * 60);
            var paddedHour    = currentHour.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0');
            var paddedMinute  = currentMinute.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0');

            timeText.text = $"{paddedHour}:{paddedMinute}";
        }
コード例 #2
0
        private void Update()
        {
            // Scale the amount of hunger to the length of the day.
            var dayRate = 1 / timeCycle.GetDayLength();

            // Reduce the hunger.
            ChangeCurrentHunger(-Time.deltaTime * hungerRate * dayRate);

            // Reduce health if the hunger is depleted (starving).
            if (currentHunger <= maxHunger * _damageThreshold)
            {
                playerHealth.ChangeHealth(-Time.deltaTime * damageRate * dayRate);
            }
        }
コード例 #3
0
        private void Update()
        {
            // Scale the amount of hunger to the length of the day.
            var dayRate = 1 / _timeCycle.GetDayLength();

            // Reduce the hunger.
            _currentThirst -= Time.deltaTime * _thirstRate * dayRate;
            // Clamp the hunger.
            _currentThirst = Mathf.Clamp(_currentThirst, 0, _maxThirst);
            // Reduce health if the hunger is depleted (starving).
            if (_currentThirst <= 0)
            {
                _playerHealth.ChangeHealth(-Time.deltaTime * _damageRate * dayRate);
            }
        }