繁体   English   中英

尝试运行此 Unity-C# 脚本时出现错误(class、结构或接口成员声明中的令牌“无效”无效)

[英]I get an error while trying to run this Unity-C# Script (Invalid token 'void' in class, struct, or interface member declaration)

public class SampleCustomHeader : MonoBehaviour
{
    const float BUTTON_HEIGHT = 50.0f;
    const string CUSTOM_HEADER_KEY_NAME = "custom_timestamp";

    WebViewObject_webviewObject

    // Use this for initialization
    void Start()
    {
        
    }
    
    // Update is called once per frame
    void Update()
    {
        
    }

    void OnGUI()
    {
        float h = Screen.height;
        if (GUI.Button(new Rect(.0f, h - BUTTON_HEIGHT, Screen.width, BUTTON_HEIGHT), "check for request header"))
        {
            this._webviewObject = GameObject.Find("WebViewObject").GetComponent<WebViewObject>();
            this._webviewObject.LoadURL("http://httpbin.org/headers");
        }
        h -= BUTTON_HEIGHT;

        if (GUI.Button(new Rect(.0f, h - BUTTON_HEIGHT, Screen.width, BUTTON_HEIGHT), "add custom header"))
        {
            this._webviewObject = GameObject.Find("WebViewObject").GetComponent<WebViewObject>();
            this._webviewObject.AddCustomHeader(CUSTOM_HEADER_KEY_NAME, System.DateTime.Now.ToString());
        }
        h -= BUTTON_HEIGHT;

        if (GUI.Button(new Rect(.0f, h - BUTTON_HEIGHT, Screen.width, BUTTON_HEIGHT), "get custom header"))
        {
            this._webviewObject = GameObject.Find("WebViewObject").GetComponent<WebViewObject>();
            Debug.Log("custom_timestamp is " + this._webviewObject.GetCustomHeaderValue(CUSTOM_HEADER_KEY_NAME));
        }
        h -= BUTTON_HEIGHT;

        if (GUI.Button(new Rect(.0f, h - BUTTON_HEIGHT, Screen.width, BUTTON_HEIGHT), "remove custom header"))
        {
            this._webviewObject = GameObject.Find("WebViewObject").GetComponent<WebViewObject>();
            this._webviewObject.RemoveCustomHeader(CUSTOM_HEADER_KEY_NAME);
        }
        h -= BUTTON_HEIGHT;

        if (GUI.Button(new Rect(.0f, h - BUTTON_HEIGHT, Screen.width, BUTTON_HEIGHT), "clear custom header"))
        {
            this._webviewObject = GameObject.Find("WebViewObject").GetComponent<WebViewObject>();
            this._webviewObject.ClearCustomHeader();
        }
        h -= BUTTON_HEIGHT;
    }
}

那里有什么问题? 我没有编写代码,但我真的需要它。 我正在运行 Unity 2020.3.5f1 Personal。 我将 Notepad++ 用于 C# 编辑器。 如果我将其删除,则会出现更多错误。

错误出现在 (18,5):错误 CS1519:class、结构或接口成员声明中的令牌“无效”无效

第 6 行:

 WebViewObject_webviewObject

我将假设您(或其他人)忘记在_之前放置一个空格,并在最后放置一个分号 ( ; )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM