I have a simple piece of code I run in Unity:
string cmd = inputField.text;
foreach (var command in _commands)
{
Debug.Log("." + command.commandPattern + ".");
Debug.Log("." + cmd + ".");
Debug.Log(String.Equals(command.commandPattern.ToString(), cmd.ToString()));
}
_commands
is a list of Command
objects and it contains one ResetCommand
which inherits from Command
. Here are the classes:
[Serializable]
public class Command
{
[SerializeField]
public string commandPattern;
public void Execute() { }
}
[Serializable]
public class ResetCommand : Command
{
public ResetCommand()
{
commandPattern = "reset";
}
public new void Execute()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
After running the code the Unity Console output looks like this:
The comparison doesn't seem to work. Any idea what I'm doing wrong here?
EDIT: Here is a screenshot of a debugger.