废话不多说,上来就是代码就是一梭子:
using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement; public class JumpScreen : MonoBehaviour { public GameObject _Slider; public Image _Image; AsyncOperation asy; bool isjump = false; bool realJump = false; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } public void LoadScreen(string ScreenName) { StartCoroutine("load", ScreenName); } IEnumerator load(string name) { if (!realJump) { realJump = true; asy = SceneManager.LoadSceneAsync(name); asy.allowSceneActivation = false; isjump = true; float bloodValue = 0; float jindutiao = 0; //while (asy.progress < 0.9f) //{ // print(_Slider.GetComponent<Slider>().value); // print(" " + asy.progress); // bloodValue = Mathf.Lerp(bloodValue, asy.progress, 0.01f); // _Slider.GetComponent<Slider>().value = bloodValue; // _Slider.GetComponent<Slider>().value = asy.progress; // yield return new WaitForEndOfFrame(); //} //_Slider.GetComponent<Slider>().value += 0.1f; //asy.allowSceneActivation = true; while (asy.progress < 0.9f) //注意不能点2次,会卡死,需要做保护处理 { bloodValue = asy.progress; while (jindutiao < bloodValue) { jindutiao += 0.1f; _Image.GetComponent<Image>().fillAmount = jindutiao; _Slider.GetComponent<Slider>().value = jindutiao; yield return new WaitForEndOfFrame(); } } bloodValue = 1; while (jindutiao < bloodValue) { jindutiao += 0.1f; _Image.GetComponent<Image>().fillAmount = jindutiao; _Slider.GetComponent<Slider>().value = jindutiao; print(jindutiao); yield return new WaitForEndOfFrame(); } asy.allowSceneActivation = true; //yield return null; } } }
