on line 31,1 I have an error, CS1022, it says type or namespace definition, or end-of-file expected. I have tried to search for the solution on google and I didn't understand it. this is the code line it is 27-36. I am using visual studio 2019 and unity 2019.4.9f1
27
public
float
counterMovement =
0
.
175f
;
28
private
float
threshold =
0
.
01f
;
29
public
float
maxSlopeAngle =
35f
;
32
33
#if (Math.Abs(wallRunCameraTilt) < maxWallRunCameraTilt && isWallRunning && isWallRight)
34
wallRunCameraTilt += Time.deltaTime* maxWallRunCameraTilt *
2
;
35
#if (Math.Abs(wallRunCameraTilt) < (maxWallRunCameraTilt) && isWallRunning && isWallLeft)
36
wallRunCameraTilt -= Time.deltaTime* maxWallRunCameraTilt *
2
;
What I have tried:
I am new to coding so I don't know what to do
You might want to learn C# before you go diving into Unity. With just that little block of code, you're missing a LOT of the basics of C#.
On line 31, you should be defining a method to contain the code for the if statements.
The if statements themselves are bad because they shouldn't be starting with a # character.
In C#, all executable code is contained in methods: only variable and class definitions can be outside - and variables need to be within a class.
So your
if
code needs to be inside a method to be effective:
private
float
myFloat =
0
.
0f
;
public
void
myMethod(
float
myParameter)
if
(myParameter ==
666
.
0f
)
}And although
#if
exists, it doesn't get executed when your code is running - it's a directive to the compiler to include or exclude code when you build the EXE file, not included in the EXE for later execution.
If you think of it like a car, when your buy a new car you select the options you want on it: black paint, 20" rims, and Cruise control for you! That provides directives to the car manufacturer when they build it:
#if (paint == Black) PaintIt(Black)
#elseif (paint = Red) PaintIt(Red)
#else PaintIt(White);
That "fixes the options" on the car, they don't change from that point on and when delivered to you it will be black, sit higher, and have an extra stick on the steering column. You can use the cruise control at any time while you drive it, but unless you selected it with
#if
when you bought the car, it doesn't exist and you can't use it.
#if
in C# code, does the same thing: selects what code is comp0iled and stored into the EXE you run later.
if
is used to make decisions when the EXE file is running and you are playing the game, reading data from a DB, or shatever you app is trying to do.
"#if (paint == Black) PaintIt(Black)
#elseif (paint = Red) PaintIt(Red)
#else PaintIt(White);"
Been told to me when i 1st learned to code i would be way head of where i am now. If you are not an instructor/ teacher, you ought to be.
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution and post a comment. Do not post your comment as a new "solution".