DNP_SineFadeText.cs 733 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace DamageNumbersPro.Demo
  6. {
  7. public class DNP_SineFadeText : MonoBehaviour
  8. {
  9. public float fromAlpha = 0.5f;
  10. public float toAlpha = 0.8f;
  11. public float speed = 4f;
  12. public float startTimeBonus = 0f;
  13. Text text;
  14. void Awake()
  15. {
  16. text = GetComponent<Text>();
  17. }
  18. void FixedUpdate()
  19. {
  20. Color color = text.color;
  21. color.a = fromAlpha + (toAlpha - fromAlpha) * (Mathf.Sin(speed * Time.unscaledTime + startTimeBonus) * 0.5f + 0.5f);
  22. text.color = color;
  23. }
  24. }
  25. }