- Home /
Really Simple C# Errors I Can't Figure Out
Usually I'm able to work through these things, but I've only a week's experience with the language and this one has stumped me. Perhaps you could help. Here's the section I'm getting errors in:
if(Input.GetKeyDown("p")){
if (Time.timeScale == 1)
Time.timeScale = 0;
Screen.showCursor = true;
else
Time.timeScale = 1;
Screen.showCursor = false;
}
}
if(Input.GetKeyDown("m")){
if (Screen.showCursor == false)
Screen.showCursor = true;
else
Screen.showCursor = false;
}
It's giving me "unexpected symbol" errors all over the place.
Assets/Cursor.cs(22,28): error CS1525: Unexpected symbol `else'
Assets/Cursor.cs(27,18): error CS1519: Unexpected symbol `if' in class, struct, or interface member declaration
Assets/Cursor.cs(27,36): error CS1519: Unexpected symbol `(' in class, struct, or interface member declaration
Assets/Cursor.cs(28,48): error CS1519: Unexpected symbol `==' in class, struct, or interface member declaration
Assets/Cursor.cs(29,51): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration
Assets/Cursor.cs(31,51): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration
Most of the errors are redundant, but I figured I'd list them anyway. I've seen if statement in if statements laid out like this in other examples, but it doesn't seem to like it here. Any suggestions?
Answer by Eric5h5 · Jan 19, 2011 at 03:36 AM
You need to put braces { } around all sections, like after the if and else statements. You can leave them out if it's just one line, but otherwise you can't.
Best not to leave them out even if it's just one line, as there's a decent chance you'll add another line later and forget to put the braces in.
Thank you so much mate really appreciate it...getting horrible amounts of errors lol :)
Your answer
