unity中怎么實現(xiàn)場景切換進度條效果,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
成都創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)公司,提供成都網(wǎng)站設(shè)計、做網(wǎng)站,網(wǎng)頁設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);可快速的進行網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,是專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
一、UI。建立slider適當(dāng)更改即可;
二、新增loadScene腳本,用來進行場景切換,將其綁定任意物體上面。博主以放置主相機為例。參數(shù)分別為進度條(用來設(shè)置value值),顯示進度文本text;
在設(shè)置中加入兩個場景:
三、腳本;
/// <summary>/// 場景切換/// 在unity 獲取當(dāng)前加載進度progress中,其中最多到0.9.只有等到加載到第二個場景才會到1/// 所有在加載進度條時如果progress的值近似0.9,則直接將進度參數(shù)設(shè)置為1,實現(xiàn)進度到100%/// 并且progress的值是在一幀加載一些資源,所以其值不會是連續(xù)的,因此設(shè)置兩個參數(shù)來記錄當(dāng)前/// 進度和頁面顯示的進度,進行++。/// </summary>public class loadScene : MonoBehaviour{ AsyncOperation async; public Slider slider; public Text text;//百分制顯示進度加載情況 void Start() { //開啟協(xié)程 StartCoroutine("loginMy"); } void Update() { } IEnumerator loginMy() { int displayProgress = 0; int toProgress = 0; AsyncOperation op = SceneManager.LoadSceneAsync(1); op.allowSceneActivation = false; while (op.progress < 0.9f) //此處如果是 <= 0.9f 則會出現(xiàn)死循環(huán)所以必須小0.9 { toProgress = (int)op.progress * 100; while (displayProgress < toProgress) { ++displayProgress; SetLoadingPercentage(displayProgress); yield return new WaitForEndOfFrame();//ui渲染完成之后 } } toProgress = 100; while (displayProgress < toProgress) { ++displayProgress; SetLoadingPercentage(displayProgress); yield return new WaitForEndOfFrame(); } op.allowSceneActivation = true; } private void SetLoadingPercentage(int displayProgress) { slider.value = displayProgress; text.text = displayProgress.ToString() + "%"; }}
看完上述內(nèi)容,你們掌握unity中怎么實現(xiàn)場景切換進度條效果的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
分享名稱:unity中怎么實現(xiàn)場景切換進度條效果
文章來源:http://www.chinadenli.net/article2/jogdic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、、網(wǎng)站收錄、軟件開發(fā)、App開發(fā)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)