简体   繁体   English

Unity 错误 CS0246:找不到类型或命名空间名称“InputField”(您是否缺少 using 指令或程序集引用?)

[英]Unity error CS0246: The type or namespace name 'InputField' could not be found (are you missing a using directive or an assembly reference?)

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class UI : MonoBehaviour
    {
    private static UI _singleton;

    private static UI Singleton
    {
        get => _singleton;
        set
        {
            if (_singleton == null)
                _singleton = value;
            else if (_singleton != value)
            {
                Debug.Log($"{nameof(UI)} instance already exists, destroying duplicate!");
                Destroy(value);
            }
        }
    }

    [Header("Connect")]
    [SerializeField] private GameObject connectUI;
    [SerializeField] private InputField usernameField;

    private void Awake()
    {
        Singleton = this;
    }

    private void ConnectClicked()
    {
        usernameField.interactable = false;
        connectUI.SetActive(false);

        NetworkManager.Singleton.Connect();
    }

    public void BackToMain()
    {
        usernameField.interactable = true;
        connectUI.SetActive(true);
    }

    public void SendName()
    {
        Message message = Message.Create(MessageSendMode.reliable, (ushort)ClientToServerId.name);
        message.AddString(usernameField.text);
        NetworkManager.Singleton.Client.Send(message);
    }    
}

The error:错误:

Unity error CS0246: The type or namespace name 'InputField' could not be found (are you missing a using directive or an assembly reference?) Unity 错误 CS0246:找不到类型或命名空间名称“InputField”(您是否缺少 using 指令或程序集引用?)

The error occurs in following line:错误发生在以下行:

[SerializeField] private InputField usernameField;

Tell me how to fix this please?请告诉我如何解决这个问题?

You need to specify the following using directive in your script, as InputField is part of the UI:您需要在脚本中指定以下 using 指令,因为 InputField 是 UI 的一部分:

using UnityEngine.UI;

or use或使用

[SerializeField] private UI.InputField usernameField;

暂无
暂无

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

相关问题 错误 CS0246:找不到类型或命名空间名称“Npgsql”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?) 错误CS0246找不到类型或名称空间名称“ Windows”(是否缺少using指令或程序集引用?) - Error CS0246 The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“StreamingContext”(是否缺少 using 指令或程序集引用?) - Error CS0246: The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“IWebHostEnvironment”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246 找不到类型或命名空间名称“CreateRandomAnswersForKey”(您是否缺少 using 指令或程序集引用?)? - Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)? 错误 CS0246:找不到类型或命名空间名称“Player”(您是否缺少 using 指令或程序集引用?) Unity - error CS0246: The type or namespace name 'Player' could not be found (are you missing a using directive or an assembly reference?) Unity CS0246:找不到类型或命名空间名称'MySql'(您是否缺少using指令或程序集引用 - CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference CS0246:找不到类型或名称空间名称“ Employee”(您是否缺少using指令或程序集引用?)? - CS0246: The type or namespace name 'Employee' could not be found (are you missing a using directive or an assembly reference?)? CS0246 找不到类型或命名空间名称“ErrorViewModel”(您是否缺少 using 指令或程序集引用?) - CS0246 The type or namespace name 'ErrorViewModel' could not be found (are you missing a using directive or an assembly reference?) C# 错误:错误 CS0246 找不到类型或命名空间名称“”(您是否缺少 using 指令或程序集引用?) - C# Error: Error CS0246 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM