ScoreFloat.cs 1.0 KB

1234567891011121314151617181920212223242526272829
  1. using TMPro;
  2. using UnityEngine;
  3. namespace Olympus
  4. {
  5. public sealed class ScoreFloat : MonoBehaviour
  6. {
  7. public TextMeshProUGUI label;
  8. public CanvasGroup group;
  9. public Vector2 restPosition;
  10. [System.NonSerialized] public OlympusGame owner;
  11. public float Age { get; private set; }
  12. public void Show(int gain)
  13. {
  14. Age=0;label.text="<size=55%>CORRECT</size>\n+"+gain;
  15. ((RectTransform)transform).anchoredPosition=restPosition;
  16. group.alpha=1;gameObject.SetActive(true);
  17. }
  18. void Update(){Advance(Mathf.Min(Time.unscaledDeltaTime,.1f));}
  19. public void Advance(float delta)
  20. {
  21. if(!gameObject.activeSelf || (owner && owner.EffectsPaused))return;
  22. Age+=Mathf.Max(0,delta);
  23. ((RectTransform)transform).anchoredPosition=restPosition+Vector2.up*(38*Mathf.Min(Age,1.2f));
  24. group.alpha=1-Mathf.Clamp01((Age-.45f)/.75f);
  25. if(Age>=1.2f)gameObject.SetActive(false);
  26. }
  27. }
  28. }