UI按钮不显示方法

时间:2015-09-29 13:55:33

标签: c# user-interface button unity3d unity5

我想创建一个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");
    }
}

未出现的方法:

Methods Not Appearing

1 个答案:

答案 0 :(得分:0)

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