- Home /
Unity throws error because of missing ":" in switch case but Visual Studio Code doesn't
Im programming a little prototype of a card game and am currently working on the function that subtracts resources based on parameters. Visual Studio Code is not giving me any errors regarding my switch case but Unity is and i have no idea why. Im using Unity 2020.3.19f1 Personal
Do I just need to not use the "or" or is this a bug in Unity?
Answer by Hellium · Oct 05, 2021 at 04:20 PM
Pattern matching enhancements is a C# 9 feature which is not supported in Unity 2020.3.
You either need to upgrade to Unity 2021.2 or simply not use the or
pattern, which can easily be replaced as follow:
case "Money":
case "money":
do something
break;
or
str = str.ToLower().Replace(' ', '_');
switch(str)
{
case "money": ...
case "prisoner": ...
...
case "broken_relic": ...
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Faulty 'unused' errors in vscode for `Update` and `Start`? 3 Answers
Distribute terrain in zones 3 Answers
Yet Another Bullet Decal Problem 0 Answers
Flip over an object (smooth transition) 3 Answers