Threat.cs 579 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using System.Collections;
  3. public class Threat
  4. {
  5. public int id;
  6. public float time;
  7. public float value = -1f;
  8. public Threat(int id, float value)
  9. {
  10. this.id = id;
  11. SetValue(value);
  12. }
  13. public void SetValue(float value)
  14. {
  15. if(GetValue() < value)
  16. {
  17. this.value = value;
  18. time = GameTime.time;
  19. }
  20. }
  21. public float GetValue()
  22. {
  23. float deltaTime = GameTime.time - time;
  24. if(deltaTime > 3f)
  25. {
  26. deltaTime = deltaTime - 3f;
  27. float modifyValue = value * (1f - deltaTime / 5f);
  28. return Mathf.Max(modifyValue, 0);
  29. }
  30. return value;
  31. }
  32. }