[英]How I - Load a new Scene by clicking a Button?
I try to figure out how to load a new scene by clicking a Button.我试图弄清楚如何通过单击按钮来加载新场景。 So i come to this logic, but it seems this is wrong.所以我来到这个逻辑,但似乎这是错误的。 Can someone help me with this?有人可以帮我弄这个吗? I really don´t get it..真没看懂。。
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LevelComplete : MonoBehaviour
{
public Button NextLevel;
public void LoadNextLevel()
{
NextLevel.onClick = SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
You will need to add a click listener to your button: https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Button-onClick.html您需要为按钮添加一个点击监听器: https : //docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.Button-onClick.html
Also, your LoadNextLevel() function is never called where the onClick could happen, so it is kind of a hen and egg problem here.此外,您的 LoadNextLevel() 函数永远不会在 onClick 可能发生的地方被调用,所以这里有点像鸡蛋和鸡蛋的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.