Item.cs 821 B

123456789101112131415161718192021222324
  1. using TMPro;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace SoftMasking.Samples {
  5. public class Item : MonoBehaviour {
  6. public Image image;
  7. public TextMeshProUGUI title;
  8. public TextMeshProUGUI description;
  9. public RectTransform healthBar;
  10. public RectTransform damageBar;
  11. public void Set(string name, Sprite sprite, Color color, float health, float damage) {
  12. if (image) {
  13. image.sprite = sprite;
  14. image.color = color;
  15. }
  16. if (title) title.text = name;
  17. if (description) description.text = "The short description of " + name;
  18. if (healthBar) healthBar.anchorMax = new Vector2(health, 1);
  19. if (damageBar) damageBar.anchorMax = new Vector2(damage, 1);
  20. }
  21. }
  22. }