Reputation: 11
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?)
The error occurs in following line:
[SerializeField] private InputField usernameField;
Tell me how to fix this please?
Upvotes: 0
Views: 2093
Reputation: 543
You need to specify the following using directive in your script, as InputField is part of the UI:
using UnityEngine.UI;
or use
[SerializeField] private UI.InputField usernameField;
Upvotes: 0