来波场景跳转----个人专用代码

本文介绍了一个Unity脚本,该脚本通过异步操作来加载游戏场景,并且在加载过程中显示进度条和当前进度百分比。具体实现包括定义一个公共类LevelLoader,继承自MonoBehaviour,其中包含用于显示加载面板的预制件、进度条滑块和进度文本等元素。LoadLevel方法接受一个整数参数作为要加载的场景索引,并启动协程LoadAsynchronously进行异步加载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class LevelLoader : MonoBehaviour {


    public GameObject loadingPanle;
    public Slider slider;
    public Text progressText;
    public void LoadLevel(int levelIndex)
    {
        StartCoroutine(LoadAsynchronously(levelIndex));
    }


    IEnumerator LoadAsynchronously(int sceneIndex)
    {
        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
        loadingPanle.SetActive(true);


        while (!operation.isDone)
        {

            float progress = Mathf.Clamp01(operation.progress / .9f);
            slider.value = progress;
            progressText.text = progress * 100 + "%";
            yield return null;
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值