【问题标题】:UI Buttons Not Showing MethodsUI 按钮不显示方法
【发布时间】:2015-12-27 01:05:45
【问题描述】:

我想制作一个 UI,让玩家可以选择继续玩游戏(关闭菜单)或转到主菜单。该代码之前运行良好,但今天,我将其加载,发现由于我正在处理的脚本不同,我的所有代码都没有编译。所以,我删除了脚本组件,然后再试一次。

我关注了recommended advice listed here,它以前工作过 - 但现在它不工作了。我不知道我做错了什么。附上我拍的一些照片和代码。任何和所有的帮助将不胜感激。

/// <summary>
/// This class controls the 'Resume Game' Button. When the button is pressed, it removes the menu, and allows the game to continue.
/// </summary>

public class ResumeButton : MonoBehaviour {

    public bool isPaused = false;
    public GameObject menu;

    public void ResumeButtonClicked()
    {
        Time.timeScale = 1;
        menu.SetActive(isPaused);
            print("It is not paused!");
            isPaused = false;
    }

    public void MainMenuButton()//There is only one button in the scene, this was code I was planning to add in. I am keeping it in here just in case it has any effect on the answer.
    {
        Application.LoadLevel("TestScene2");
    }
}

方法未出现:

【问题讨论】:

  • 如果你使用 svn 或 git,回去会容易得多。
  • 您是否将 ResumeButton 脚本添加回您的 ButtonController?
  • @Oliver 也许,但事后看来是 20/20。所以,我现在需要专注于解决问题,而不是弄清楚如何为将来保存代码。 JamesHogle 是的,我做到了。没有骰子。
  • 如果你没有版本控制系统,我会建立一个新的(空的)项目并开始将部分从不工作的部分复制到香草系统,并在每一步之后检查它是否工作预期的。然后你可能会知道错误在哪里。
  • 谢天谢地,我确实保存了旧版本的文件,所以我可以使用它。我将保持这个问题的开放性,以便我可以找出这个问题发生了什么。

标签: c# user-interface button unity3d unity5


【解决方案1】:

对不起,我还不能发表评论,所以这是我的“评论”:
确保将 ResumeButton MonoBehaviour 保存为 ResumeButton.cs 脚本(cs 文件和类名需要相同)。还要仔细检查您提供给 onClick 事件监听器列表的对象是否确实是附加了 ResumeButton MonoBehaviour 脚本的对象。
目前,我可以从您提供的图像中看到,您有一个 ButtonController 脚本附加到您尝试从 onClick 事件调用的游戏对象,它只会显示您在 ButtonController.cs 脚本中公开的函数.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    相关资源
    最近更新 更多