【发布时间】:2021-11-27 12:56:00
【问题描述】:
所以我一直在尝试制作游戏,但是当我按下按钮时,场景会自行重新加载。我想要做的是让它在加载场景时获取活动场景的构建索引。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelSwitch : MonoBehaviour
{
int CurrentSceneBuildIndex;
bool sceneLoaded;
void Update()
{
if (sceneLoaded == true )
{
CurrentSceneBuildIndex = SceneManager.GetActiveScene().buildIndex;
}
}
public void NextLevel()
{
SceneManager.LoadScene(CurrentSceneBuildIndex + 3 );
sceneLoaded = true;
}
public void LevelSelect()
{
SceneManager.LoadScene("LevelSelect");
}
}
【问题讨论】:
-
看看如何写一个好问题:stackoverflow.com/tour。您想问的问题适用于 StackOverflow,但需要重写才能对其他人有用并避免投票。你能写一个更具体的问题吗? “所以我一直在尝试制作游戏”什么也没说,“当我按下按钮时”——什么按钮?我想你真正想问的是“如何获取活动场景的构建索引?”其次是“这是我尝试过的......这就是发生的事情......”