DropUnit.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class DropUnit : MonoBehaviour
  7. {
  8. public Text nameText;
  9. public Text digitText;
  10. public Image image;
  11. public GameObject bingObj;
  12. public Sprite[] sprites;
  13. private int index = 0;
  14. private float currentIndex = 0;
  15. public void Init(double lgtd,double lttd,string na,string di)
  16. {
  17. Vector3 temp = CoordinateConverter.GeoToUGUISmall(lgtd, lttd);
  18. this.GetComponent<RectTransform>().anchoredPosition3D = temp;
  19. image.sprite = sprites[0];
  20. nameText.text = na;
  21. digitText.text = di;
  22. currentIndex = 0;
  23. index = (int)Mathf.Clamp(Mathf.Round(float.Parse(di) / 2.0f), 0,9);
  24. }
  25. void Update()
  26. {
  27. this.GetComponent<RectTransform>().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width;
  28. if (index > currentIndex) {
  29. //Debug.Log((int)(currentIndex));
  30. currentIndex += Time.deltaTime;
  31. image.sprite = sprites[(int)(currentIndex)];
  32. }
  33. }
  34. }