using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class WeatherUnit : MonoBehaviour { public Text nameText; public Text dropText; public Image image; public GameObject[] weatherSprite; public Sprite[] sprites; public GameObject bingObj; private int index = 0; private float currentIndex = 0; // Start is called before the first frame update void Start() { } public void Init(double lgtd, double lttd, string na, string we,float drop) { for (int i = 0; i < weatherSprite.Length; i++) { weatherSprite[i].gameObject.SetActive(false); } dropText.text = drop.ToString(); Vector3 temp = CoordinateConverter.GeoToUGUISmall(lgtd, lttd); this.GetComponent().anchoredPosition3D = temp; nameText.text = na.Trim(); image.sprite = sprites[0]; currentIndex = 0; index = (int)Mathf.Clamp(Mathf.Round(drop / 2.0f), 0, 9); switch (we) { case "9": weatherSprite[0].gameObject.SetActive(true); break; case "8": weatherSprite[1].gameObject.SetActive(true); break; case "7": weatherSprite[2].gameObject.SetActive(true); break; case "6": weatherSprite[3].gameObject.SetActive(true); break; case "5": weatherSprite[4].gameObject.SetActive(true); break; } } // Update is called once per frame void Update() { this.GetComponent().anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(bingObj.transform.position) * 1920.0f / Screen.width; if (index > currentIndex) { //Debug.Log((int)(currentIndex)); currentIndex += Time.deltaTime; image.sprite = sprites[(int)(currentIndex)]; } } }