I keep getting the message "CS1519 - Invalid token "if" in class." How can I resolve this?

Hey, can someone help me with this bug I found? I’m having a little trouble finishing a game i’m working on, and it’s a real snag? Does anyone have any expertise on the matter?

I found something on Unity Support The CS1519 error is caused when a token is in a location that it does not belong. To fix the CS1519 error you will need to ensure that there is only one user defined identifier for each method, class or variable declaration. If you are declaring multiple variables of the same type then ensure they are separated using commas.

Yes, you have left code outside of any function block. That’s the problem, nothing to do with commas or anything else.

Tuck your code back in where it belongs.

Remember the two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.