DNP_PrefabSettings.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. namespace DamageNumbersPro.Demo
  6. {
  7. public class DNP_PrefabSettings : MonoBehaviour
  8. {
  9. [Header(" \nThis component is only for the demo scene.\nYou don't need it in your prefabs.\n ")]
  10. public int damage = 1;
  11. public int numberRange = 100;
  12. public List<string> texts;
  13. public List<TMP_FontAsset> fonts;
  14. public bool randomColor;
  15. public void Apply(DamageNumber target)
  16. {
  17. if (texts != null && texts.Count > 0)
  18. {
  19. int randomIndex = Random.Range(0, texts.Count);
  20. target.leftText = texts[randomIndex];
  21. if(fonts != null && randomIndex < fonts.Count)
  22. {
  23. target.SetFontMaterial(fonts[randomIndex]);
  24. }
  25. if(texts.Count > 1)
  26. {
  27. target.enableNumber = false;
  28. }
  29. }
  30. if (randomColor)
  31. {
  32. target.SetColor(Color.HSVToRGB(Random.value, 0.5f, 1f));
  33. }
  34. }
  35. }
  36. }