[英]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.