Unity: How to Regenerate Values (like Health) over time

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 3

  • @Droppa1
    @Droppa1 Місяць тому

    wb

  • @Droppa1
    @Droppa1 Місяць тому +1

    Health.cs you shouldn't use Time.time to control RegenCanStart. If you do then when you pause the game in the editor, or hit a breakpoint, or even save the game the timer is still going and when you come back regen will start. Rather in OnTakeDamage *set* startRegenTime to timeBetweenDamageAndRegen, then in Update, subtract Time.deltaTime from startRegenTime as long as it's > 0.

    • @FeedMyKids1
      @FeedMyKids1  Місяць тому

      Incorrect:
      Pausing the game (timescale 0) doesn't affect it.
      Pausing the Game tab from the editor doesn't affect it.
      Pausing using Debug.Break doesn't affect it.
      Saving does not affect it. Save a value like "TimeUntilRegenStarts" (value = startRegenTime - Time.time) and upon load do "startRegenTime = Time.time + TimeUntilRegenStarts"