; expected
This error occurs in two situations:
First, check if your statement requires a semicolon.
Semicolon required
Don't use a semicolonwhile in the do statement)throw)checked and unchecked, fixed, and lock statements.using statement (excluding when used as a declaration)Statements followed by a block are the common place to exclude a semicolon, blocks are often defined by their opening and closing braces, { and }, which can sometimes be omitted in single-line cases.
If you use a semicolon after a block statement it will become an empty statement, and the following block will be disconnected from the preceding statement, causing it to do nothing.
if (example == null); // <- extra semicolon (;)
{
Debug.Log($"{nameof(example)} is null!"); // This will always print because the previous selection statement has a semicolon!
}If you are confused, look at example code to see if yours needs a semicolon.
Add a semicolon ; to the end of your line.
If all errors on that line go away, it's likely the correct solution. Otherwise you may have an incorrectly written statement.
public void Start()
{
transform.position = _targetPosition;
transform.rotation = _targetRotation // Missing semicolon, add a ; here.
}If your error isn't underlined in red you must configure your IDE.
Statements can be written incorrectly in extremely varied ways. Compare your code structure with a functioning example to see what you're missing.
Whitespace (spaces, tabs, and newlines) is not significant in C#, functionally a piece of code can have all tabs and newlines removed and it will still run1, you can also add extra newlines to make multi-line statements. We instead require a terminator to tell the compiler where a statement begins and ends.
Spaces may be significant when separating keywords and names. Whitespace is significant inside of strings and characters.↩