当前位置:网站首页>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");
}
边栏推荐
- Correspondence between IEC61131 data type and C data type
- AQS唤醒线程的时候为什么从后向前遍历,我懂了
- nacos注册中心
- Date and time function of MySQL function summary
- What are the characteristics of the grammar of Russian documents in the translation of scientific papers
- Teach you how to use code to realize SSO single sign on
- Black eat black? The man cracked the loopholes in the gambling website and "collected wool" for more than 100000 yuan per month
- [acwing] 1268. Simple questions
- 域名解析过程全分析,就着文字理解更佳
- webassembly 01基本资料
猜你喜欢

C语言——指针一点通※

推荐12个免费查找文献的学术网站,建议点赞、收藏!

Excel VBA: realize automatic drop-down filling formula to the last line

Redis expiration deletion strategy and memory obsolescence strategy

嵌入式分享合集21

How to reproduce the official course of yolov5 gracefully (II) -- Mark and train your own data set

Briefly describe the application fields of WMS warehouse management system

C语言力扣第41题之缺失的第一个正数。两种方法,预处理快排与原地哈希

一次线上事故,我顿悟了异步的精髓

The landing of tdengine in the GPS and AIS scheduling of Zhongtian steel
随机推荐
Test of countlaunch demo
图像非局部均值滤波的原理
[Luogu] p1383 advanced typewriter
Please elaborate on the implementation principle of synchronized and related locks
An online accident, I suddenly realized the essence of asynchrony
Icml2022 | imitation learning by evaluating the professional knowledge of the presenter
AXI协议(4):AXI通道上的信号
STM32 development | ad7606 parallel multi-channel data acquisition
遥感、GIS和GPS技术在水文、气象、灾害、生态、环境及卫生等领域中的应用
There was an unexpected error (type=Method Not Allowed, status=405).记录报错
What are the characteristics of the grammar of Russian documents in the translation of scientific papers
MySQL八股知识点:从入门到删库
The pit of history can only be filled up as far as possible
Google Emoji guessing game helps parents guide their children to surf the Internet safely
The importance of supporting horizontal expansion of time series database
C语言——指针一点通※
What points should be paid attention to in the selection of project management system?
Good at C (summer vacation daily question 6)
How to connect tdengine through idea database management tool?
JVM第二讲:类加载机制