ItemResult.cs 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public class ItemResult : MonoBehaviour {
  5. public Text rankTxt;
  6. public Text nickTxt;
  7. public Text killTxt;
  8. public Text deadTxt;
  9. public Image bgImage;
  10. void Awake()
  11. {
  12. string name = this.gameObject.name;
  13. int index = int.Parse(name.Substring(5));
  14. RectTransform rt = GetComponent<RectTransform>();
  15. Vector3 pos = rt.localPosition;
  16. pos.y = 285-index*30f;
  17. rt.localPosition = pos;
  18. }
  19. public void SetData(int rank, PlayerStatsData data, Sprite bgSprite, bool isMe=false)
  20. {
  21. if(rank > 0)
  22. {
  23. bgImage.enabled = true;
  24. rankTxt.text = rank.ToString();
  25. nickTxt.text = data.nick;
  26. killTxt.text = data.kill.ToString();
  27. deadTxt.text = data.death.ToString();
  28. bgImage.sprite = bgSprite;
  29. if(isMe)
  30. rankTxt.color = nickTxt.color =
  31. killTxt.color = deadTxt.color = new Color(1f, 0.5f, 0);
  32. }
  33. else
  34. {
  35. rankTxt.text =
  36. nickTxt.text =
  37. killTxt.text =
  38. deadTxt.text = "";
  39. bgImage.enabled = false;
  40. }
  41. }
  42. }