Click here to Skip to main content
15,028,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
 27  public float counterMovement = 0.175f;
 28  private float threshold = 0.01f;
 29  public float maxSlopeAngle = 35f;
 30  
 31  {
 32      //While Wallrunning camera tilts
 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
Posted
Updated 2-Dec-20 23:41pm
v2
Comments
PIEBALDconsult 2-Dec-20 23:52pm
   
Well, that doesn't look much like C#

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:
C#
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:
C#
#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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900