当前位置:网站首页>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");
}
边栏推荐
- pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0
- Axi protocol (5): burst mechanism of Axi protocol
- Stm32fsmc extended SRAM
- Icml2022 | imitation learning by evaluating the professional knowledge of the presenter
- What are the well-known to-do apps at home and abroad
- 有ggjj看看这个问题没,是否缓存导致跨域问题?
- Full analysis of domain name resolution process means better text understanding
- JVM Lecture 6: how to solve the frequent FGC in online environment?
- Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month
- AXI协议(5):AXI协议的burst机制
猜你喜欢
随机推荐
Nacos registry
Ggjj, do you have a look at this problem? Does caching cause cross domain problems?
黑吃黑?男子破解赌博网站漏洞,每月“薅羊毛”10多万元
nacos注册中心
Stm32fsmc extended SRAM
Test of countlaunch demo
[mathematical modeling] basic knowledge of MATLAB
Redis expiration deletion strategy and memory obsolescence strategy
Redis过期删除策略和内存淘汰策略
C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希
嵌入式分享合集20
Use field parameters for report translation
Nacos 介绍和部署
Seata两阶段提交AT详解
CMD operation command
Correspondence between IEC61131 data type and C data type
【ACWing】1268. 简单题
分子骨架跃迁工具-DeLinker介绍
Can serial port can 232 can 485 serial port to CANbus bus gateway module can232/485mb converter cancom
Annotation @autowired how to assemble automatically









