Hello all,
I am somewhat new to coding in C#. On a scale of 1 to 10, my level of understanding would probably be a 3 or a 4. I’ve been practicing on Unity for a few weeks, and almost have a complete game to show for it. However, I unexpectedly ran into an error with “if” statements.
Every time I add an “if” statement to a new script, I get the CS1519 compiler error, along with several other errors which seem to result from the “if” statement not being recognized by the compiler for what it is. I only run into this issue when creating a new script; when I compile scripts which I have made previously, I do not get this error, even when they contain “if” statements. I updated Microsoft Visual Studio immediately before I ran into this issue, so I suspect that this may be the cause of my problem.
Here’s a code which boils it down. The filename is “LevelPicker.cs”.
using UnityEngine;
using Debug = UnityEngine.Debug;
public class LevelPicker : MonoBehaviour
{
int a = 1;
int b = 2;
if (a < b)
{
Debug.Log("The code works.")
}
}
Here’s the list of errors generated when I compile the code:
CS1519 Invalid token ‘if’ in class, struct, or interface member declaration
CS1003 Syntax error, ‘,’ expected
CS8124 Tuple must contain at least two elements.
CS1003 Syntax error, ‘>’ expected
CS1026 ) expected
CS1519 Invalid token ‘{’ in class, struct, or interface member declaration
CS1519 Invalid token ‘(’ in class, struct, or interface member declaration
CS1031 Type expected
CS8124 Tuple must contain at least two elements.
CS1519 Invalid token ‘“The code works.”’ in class, struct, or interface member declaration
CS1026 ) expected
CS1022 Type or namespace definition, or end-of-file expected