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);
    }
}

It said that I’m wrong on this line:
[SerializeField] private InputField usernameField;

Please tell me how to fix it?

Hello.

When having this kind og problems, rightclick on the error line (marked with a red underline) and will see it says “Add using…”

Also, loot always at the scripting manuals,

Will see on top of script you need to add a namespace or library to use that kind of variable.

In your case:

using UnityEngine.UI; // Required when Using UI elements.

Bye!