我不能让自定义GUIskin工作

时间:2015-06-12 00:45:00

标签: c# unity3d

我有这段代码

using UnityEngine;
using System.Collections;

public class InfoInput : MonoBehaviour {

    public string charname  = "Name";
    public string usrname   = "User Name";
    public string charrace  = "Race";
    public string charclass = "Class";
    public string charalli  = "LG";
    public string next      = "Next";

    void OnGUI() {
        int x      = 500;
        int y      = 150;
        int w      = 260;
        int h      = 20;
        int buffer = 6;

        charname  = GUI.TextField (new Rect (x, y, w, h), charname, 24, CustomGUI);
        y = y + h + buffer;
        usrname   = GUI.TextField (new Rect (x, y, w, h), usrname, 24, CustomGUI);
        y = y + h + buffer;
        charrace  = GUI.TextField (new Rect (x, y, w, h), charrace, 12, CustomGUI);
        y = y + h + buffer;
        charclass = GUI.TextField (new Rect (x, y, w, h), charclass, 20, CustomGUI);
        y = y + h + buffer;
        charalli  = GUI.TextField (new Rect (x, y, w, h), charalli, 2, CustomGUI);
        y = y + h + buffer;
       GUI.Button (new Rect (x, y, w, y / 4), next, CustomGUI);  
    }
}

并且它没有从CustomGUI加载.guiskin是我在这里缺少的东西(手册没有告诉我如何使用它)当我运行脚本时它返回一个错误,说我的CustomGUI不是有效的参考

1 个答案:

答案 0 :(得分:1)

我没有看到您在上面的代码中声明了GUI Skin的位置。

using UnityEngine;
using System.Collections;


public class InfoInput : MonoBehaviour {

    public string charname  = "Name";
    public string usrname   = "User Name";
    public string charrace  = "Race";
    public string charclass = "Class";
    public string charalli  = "LG";
    public string next      = "Next";

    public GUISkin CustomGUI // Add the from the Inspector panel by drag and drop

    void OnGUI() {
        int x      = 500;
        int y      = 150;
        int w      = 260;
        int h      = 20;
        int buffer = 6;

        charname  = GUI.TextField (new Rect (x, y, w, h), charname, 24, CustomGUI);
        y = y + h + buffer;
        usrname   = GUI.TextField (new Rect (x, y, w, h), usrname, 24, CustomGUI);
        y = y + h + buffer;
        charrace  = GUI.TextField (new Rect (x, y, w, h), charrace, 12, CustomGUI);
        y = y + h + buffer;
        charclass = GUI.TextField (new Rect (x, y, w, h), charclass, 20, CustomGUI);
        y = y + h + buffer;
        charalli  = GUI.TextField (new Rect (x, y, w, h), charalli, 2, CustomGUI);
        y = y + h + buffer;
       GUI.Button (new Rect (x, y, w, y / 4), next, CustomGUI);  
    }
}

如果您还没有,请右键单击Assets选项卡,在Assets文件夹中创建GUISkin,转到Create>GuiSkin。然后,您可以将皮肤添加到其中,然后将其拖到“检查器”面板中以供使用。

希望它有所帮助。