Actually adding to what Job said. Any single conditional statement must have an l-value and an r-value, where l and r just mean left and right. Your original statement has 2 conditions, with only one l-value and 2 r-values.
In the vein of what you were wanting to do. You can use ToLower() like Leon said. You can also create what are called Extension Methods that add functionality to existing classes in C#. Below I’ll paste in some code where you can add a Has method to the string class that allows you to specific whether or not you want the check to be case sensitive or not and let’s you list any number of arguments to check against and shows an example and the output in Unity via screen snip.
using UnityEngine;
public static class ExtensionMethods {
public static bool Has(
this string thisString,
bool isCaseSensitive,
params string[] thoseStrings
) {
var leftString = thisString;
if(!isCaseSensitive)
leftString = thisString.ToLower();
foreach (var currentString in thoseStrings) {
var rightString = currentString;
if(!isCaseSensitive)
rightString = currentString.ToLower();
if (leftString == rightString)
return true;
}
return false;
}
}
And here is the example usage of it.
var testString = "fEmAlE";
print(
"testString.Has(true, \"car\", \"man\", \"female\") == " +
testString.Has(true, "car", "man", "female")
);
print(
"testString.Has(false, \"car\", \"man\", \"female\") == " +
testString.Has(false, "car", "man", "female")
);
As you can see in the screen snip below where I tested it in Unity console, the first one I tell it isCaseSensitive is true, so it checks the exact values…which you want sometimes, for instance checking a password. But for times like what you are doing, not. So on the second one you can see I passed false to isCaseSensitive, and the result shows that it evaluated to True even those the case didn’t match, but the characters themselves did.
The extra stuff I threw in there like params string[] thoseStrings, is a way of allowing you to pass as many arguments of a single type as you like to a method and you can access it via an array. This allows you to use it intuitively like what you tried with if(this == “this” || “that”). You can just use the .Has method on any string you have like yourString.Has(false, “this”, “that”). You could remove the bool isCaseSensitive parameter if you wanted to avoid having to specify every time, or make another method called HasCase() or something that is like the one I have for those occasions. In that case you’d have 2 methods that have a quality they omit and no need for the extra parameter.
Anyway, I hope any of that was useful.