【问题标题】:Start a new scene when the button is clicked?单击按钮时开始一个新场景?
【发布时间】:2021-01-15 10:48:55
【问题描述】:

单击按钮时我需要开始一个新场景,但是当我单击它时 - 没有任何反应;有什么问题?

public class Options : MonoBehaviour
{
public Button button;

// Start is called before the first frame update
void LoadOptions()
{
  button.GetComponent<Button>();
   button.onClick.AddListener(LoadScene);
   
}
// loading scene
void LoadScene()
{
    SceneManager.LoadScene("Options");
}
}

当我点击它时 - 什么也没有发生;有什么问题? 我在我的项目中添加了一个名为“Options”的场景。

【问题讨论】:

    标签: c# android unity3d augmented-reality


    【解决方案1】:

    不要这样做,只需将脚本添加到作为按钮父级的空游戏对象中,然后添加:

    public void ChangeScene()
    {
    SceneManager.LoadScene("Options");
    }
    

    然后在按钮的OnClick中添加空的gameObject,然后选择ChangeScene,如果按钮光线投射好并且没有任何阻挡它,它将起作用很好

    如果您不想使用场景名称,您可以LoadScene(0),但在构建设置中拖动场景以查看其索引

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 2015-09-07
      • 2017-09-11
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      • 2013-04-10
      • 1970-01-01
      相关资源
      最近更新 更多