当前位置:网站首页>unity场景跳转脚本
unity场景跳转脚本
2022-07-26 05:04:00 【你只在游戏中存在】
1.跳转的场景需要加入buildsetting
2.场景跳转脚本 这里采用异步加载
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class SceneManager : MonoSingleton<SceneManager>
{
public UnityAction<float> onProgress = null;
public UnityAction onSceneLoadDone = null;
// Use this for initialization
protected override void OnStart()
{
}
// Update is called once per frame
void Update () {
}
public void LoadScene(string name)
{
StartCoroutine(LoadLevel(name));
}
IEnumerator LoadLevel(string name)
{
Debug.LogFormat("LoadLevel: {0}", name);
AsyncOperation async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(name);
async.allowSceneActivation = true;
async.completed += LevelLoadCompleted;
while (!async.isDone)
{
if (onProgress != null)
onProgress(async.progress);
yield return null;
}
}
private void LevelLoadCompleted(AsyncOperation obj)
{
if (onProgress != null)
onProgress(1f);
Debug.Log("LevelLoadCompleted:" + obj.progress);
if (onSceneLoadDone != null)
onSceneLoadDone();
}
}
3.调用
void OnLogin(Result result, string msg)
{
Debug.Log("dasaaaaaaaa");
SceneManager.Instance.LoadScene("CharacterSelect");
}
边栏推荐
- Icml2022 | imitation learning by evaluating the professional knowledge of the presenter
- Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
- 安装NCCL\mpirun\horovod\nvidia-tensorflow(3090Ti)
- Axi protocol (5): burst mechanism of Axi protocol
- 未来大气污染变化模拟
- Redis solves the problem of oversold inventory
- BigDecimal 的 4 个坑,你踩过几个?
- Excel vba: saving multiple worksheets as new files
- Molecular skeleton transition tool -delinker introduction
- Test of countlaunch demo
猜你喜欢
随机推荐
[weekly translation go] how to write your first program with go
手把手教你用代码实现SSO单点登录
I talked with the interviewer about MySQL optimization in five dimensions
Annotation @autowired how to assemble automatically
面试之请详细说下synchronized的实现原理以及相关的锁
[cloud native | 17] four network modes of container
【洛谷】P3919 【模板】可持久化线段树1(可持久化数组)
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly 100 times the improvement of analysis performance
提高shuffle操作中的reduce并行度
What are the demand management software for small and medium-sized enterprises
Icml2022 | imitation learning by evaluating the professional knowledge of the presenter
Add and modify the verification logic, and use -validation- to complete the group verification
Full analysis of domain name resolution process means better text understanding
Learn to map with nature medicine -- complex heat map
Torch slice maintenance
Mysql主从同步及主从同步延迟解决方案
如何优雅的复现YOLOv5官方历程(二)——标注并训练自己的数据集
Have you known several distribution methods of NFT? What are the advantages and disadvantages of different distribution methods?
Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month
Axi protocol (4): signals on the Axi channel









