跳转到主要内容

场景&&场景切换

一个screen就是一个场景(关卡),多个场景之间切换代码如下

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LoadScreen : MonoBehaviour
{

    public string SceneName = "SampleScene";
    public float Delay = 5f;
    void Start()
    {
        // 5秒后自动切换场景
        StartCoroutine(ChangeSceneAfterDelay(Delay));
    }
    // 切换场景
    private IEnumerator ChangeSceneAfterDelay(float delay)
    {
        // 等待delay秒
        yield return new WaitForSeconds(delay);
        // 切换场景
        UnityEngine.SceneManagement.SceneManager.LoadScene(SceneName);
    }
    void Update()
    {

    }
}