Unity clicks the button to jump to the page

Save time: the complete code is at the bottom

1. Import namespace

using UnityEngine.SceneManagement;

2. (1) Destroy the previous scene after switching scenes

public void S1()
{
    SceneManager.LoadScene("Menu_Setting");//场景名称
    SceneManager.LoadScene(1);//场景索引
}

(2) Do not destroy the previous scene after switching scenes

public void S1()
{
    SceneManager.LoadScene("Menu_Setting",LoadSceneMode.Additive);//场景名称
    SceneManager.LoadScene(1,LoadSceneMode.Additive);//场景索引
}

3. Mount the script to the button and add a button click event.

Complete code

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

public class Scene_Jump : MonoBehaviour
{
    public void S1()
    {
        SceneManager.LoadScene("Menu_Setting");
    }
}

Guess you like

Origin blog.csdn.net/clown_sam/article/details/132701422