Hello fellow developers
Im running into a few errors. I am trying to write a console for my game. I followed a youtube tutorial
I have to remove override from public override string cName { get; protected set; } and other variables to get anything to work then I start to get this error.
Assets/Scripts/Console/CommandQuit.cs(7,15): error CS0534: InGameConsole.CommandQuit' does not implement inherited abstract member
InGameConsole.ConsoleCommand.cName.get
CommandQuit.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace InGameConsole
{
public class CommandQuit : ConsoleCommand
{
public override string cName { get; protected set; }
public override string cCommand { get; protected set; }
public override string cDescription { get; protected set; }
public override string cHelp { get; protected set; }
public CommandQuit()
{
cName = "Quit";
cCommand = "quit";
cDescription = "Quits the application";
cHelp = "Use this command with no arguments to force Unity to quit!";
AddCommandToConsole();
}
public override void RunCommand()
{
if (Application.isEditor)
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
}
else
{
Application.Quit();
}
}
public static CommandQuit CreateCommand()
{
return new CommandQuit();
}
}
}
DeveloperConsole.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace InGameConsole
{
public abstract class ConsoleCommand
{
public abstract string cName { get; protected set; }
public abstract string cCommand { get; protected set; }
public abstract string cDescription { get; protected set; }
public abstract string cHelp { get; protected set; }
public void AddCommandToConsole()
{
string addMessage = " command has been added to the console.";
DeveloperConsole.AddCommandsToConsole(cCommand, this);
DeveloperConsole.AddStaticMessageToConsole(cName + addMessage);
}
public abstract void RunCommand();
}
public class DeveloperConsole : MonoBehaviour
{
public static DeveloperConsole Instance { get; private set; }
public static Dictionary<string, ConsoleCommand> Commands { get; private set; }
[Header("UI Components")]
public Canvas consoleCanvas;
public ScrollRect scrollRect;
public Text consoleText;
public Text inputText;
public InputField consoleInput;
private void Awake()
{
if(Instance != null)
{
return;
}
Instance = this;
Commands = new Dictionary<string, ConsoleCommand>();
}
private void Start()
{
consoleCanvas.gameObject.SetActive(false);
CreateCommands();
}
private void CreateCommands()
{
CommandQuit commandQuit = CommandQuit.CreateCommand();
}
public static void AddCommandsToConsole(string _name, ConsoleCommand _command)
{
if(!Commands.ContainsKey(_name))
{
Commands.Add(_name, _command);
}
}
private void Update()
{
//if(Input.GetKeyDown(KeyCode.BackQuote))
//{
// consoleCanvas.gameObject.SetActive(!consoleCanvas.gameObject.activeInHierarchy);
//}
if(consoleCanvas.gameObject.activeInHierarchy)
{
if(Input.GetKeyDown(KeyCode.Return))
{
if(inputText.text != "")
{
AddMessageToConsole(inputText.text);
ParseInput(inputText.text);
}
}
}
}
private void AddMessageToConsole(string msg)
{
consoleText.text += msg + "\n";
scrollRect.verticalNormalizedPosition = 0f;
}
public static void AddStaticMessageToConsole(string msg)
{
DeveloperConsole.Instance.consoleText.text += msg + "\n";
DeveloperConsole.Instance.scrollRect.verticalNormalizedPosition = 0f;
}
private void ParseInput(string input)
{
string[] _input = input.Split(null);
if (_input.Length == 0 || _input == null)
{
AddMessageToConsole("Command not recognized.");
return;
}
if (!Commands.ContainsKey(_input[0]))
{
AddMessageToConsole("Command not recognized.");
}
else
{
Commands[_input[0]].RunCommand();
}
}
}
}