using UnityEngine; using System.Collections; using UnityEngine.UI; public class SliderProgress : MonoBehaviour { float currentAmount = 0; public float targetProcess = 100; float speed = 0.1f; public GameObject Slider; private Text m_text; public Button OK; // Use this for initialization void Start () { m_text = transform.Find("ProgressReport").gameObject.GetComponent(); } // Update is called once per frame void Update() { //Fix me...... if (currentAmount < targetProcess && m_text.text!=null) { //Debug.Log("currentAmount:" + currentAmout.ToString()); currentAmount += speed; if (currentAmount > targetProcess) currentAmount = targetProcess; m_text.text= m_text.text.Substring(0,3) + ((int)currentAmount).ToString() + "%"; Slider.GetComponent().value = currentAmount / 100.0f; } else { m_text.text = m_text.text.Substring(1, 3) + "完毕,请关闭窗口!"; OK.gameObject.SetActive(true); OK.onClick.AddListener(delegate () { Destroy(gameObject); }); } } }