Search Unity

Parsing Error CS8025

Discussion in 'Scripting' started by FinlayHanlon, Jul 24, 2014.

  1. FinlayHanlon

    FinlayHanlon

    Joined:
    Dec 10, 2013
    Posts:
    46
    I'm literally ripping my hair out cause of this :mad:

    I've checked this mecanim several times and I keep getting a parsing error CS8025 at lines (4,1), here is the full script. I understand that a parsing error is a syntax error in my script writing - so I've checked that the wiggly brackets all add up and its still giving me this error. Can someone please correct my CSharp script so it works?

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. {
    5. private Vector3 lastLeftStickInputAxis; // stores the axis input from the left stick between frames
    6. }
    7. private void Update()
    8. {
    9.     /* START LOCOMOTION */
    10.    
    11.     // Get the axis from the left stick (a Vector2 with the left stick's direction)
    12.     var leftStickInputAxis = inputManager.LeftAxis;
    13.    
    14.     // Get the angle between the the direction the model is facing and the input axis vector
    15.     var a = SignedAngle(new Vector3(leftStickInputAxis.x, 0, leftStickInputAxis.y), model.transform.forward);
    16.    
    17.     // Normalize the angle
    18.     if (a < 0)
    19.     {
    20.         a *= -1;
    21.     }
    22.     else
    23.     {
    24.         a = 360 - a;
    25.     }
    26.    
    27.     // Take into consideration the angle of the camera
    28.     a += Camera.main.transform.eulerAngles.y;
    29.    
    30.     var aRad = Mathf.Deg2Rad*a; // degrees to radians
    31.    
    32.     // If there is some form of input, calculate the new axis relative to the rotation of the model
    33.     if (leftStickInputAxis.x != 0 || leftStickInputAxis.y != 0)
    34.     {
    35.         leftStickInputAxis = new Vector2(Mathf.Sin(aRad), Mathf.Cos(aRad));
    36.     }
    37.    
    38.     float xVelocity = 0f, yVelocity = 0f;
    39.     float smoothTime = 0.05f;
    40.    
    41.     // Interpolate between the input axis from the last frame and the new input axis we calculated
    42.     leftStickInputAxis = new Vector2(Mathf.SmoothDamp(lastLeftStickInputAxis.x, leftStickInputAxis.x, ref xVelocity, smoothTime), Mathf.SmoothDamp(lastLeftStickInputAxis.y, leftStickInputAxis.y, ref yVelocity, smoothTime));
    43.    
    44.     // Update the Animator with our values so that the blend tree updates
    45.     animator.SetFloat("Walk", leftStickInputAxis.x);
    46.     animator.SetFloat("Turn", leftStickInputAxis.y);
    47.    
    48.     lastLeftStickInputAxis = leftStickInputAxis;
    49.    
    50.     /* END LOCOMOTION */
    51.    
    52.    
    53.    
    54.     /* START ROTATION */
    55.    
    56.     // Get the axis from the right stick (a Vector2 with the right stick's direction)
    57.     var rightStickInputAxis = inputManager.RightAxis;
    58.     if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0)
    59.     {
    60.         float angle2 = 0;
    61.         if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0)
    62.         {
    63.             angle2 = Mathf.Atan2(rightStickInputAxis.x, rightStickInputAxis.y)*Mathf.Rad2Deg;
    64.             if (angle2 < 0)
    65.             {
    66.                 angle2 = 360 + angle2;
    67.             }
    68.         }
    69.        
    70.         // Calculate the new rotation for the model and apply it
    71.         var rotationTo = Quaternion.Euler(0, angle2 + Camera.main.transform.eulerAngles.y, 0);
    72.         model.transform.rotation = Quaternion.Slerp(model.transform.rotation, rotationTo, Time.deltaTime*10);
    73.     }
    74.    
    75.     /* END ROTATION */
    76. {
    77. private float SignedAngle(Vector3 a, Vector3 b)
    78.  
    79.     return Vector3.Angle(a, b) * Mathf.Sign(Vector3.Cross(a, b).y);
    80. }
    81. }

    Thanks
    -Finlay Hanlon
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You have no class declaration.

    --Eric
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    That's.... quite a mess, actually. The simplest recommendation is, create a new C# script from Unity (so that it shows you the correct syntax for declaring a class, which is required and completely absent from your pasted code).

    At the end of your script... I have no idea what's going on there, and neither does the compiler. After "END ROTATION", shouldn't that be a } not a { ? As it is you just have random curly brackets strewn around, and "private" variables declared in a place they have no business being declared.... no wait, that's a function.... but there's no open curly bracket after the function....

    Yeah, it's a mess.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class YourScriptNameHere : MonoBehaviour
    5. {
    6. private Vector3 lastLeftStickInputAxis; // stores the axis input from the left stick between frames
    7.  
    8. private void Update()
    9. {
    10.    /* START LOCOMOTION */
    11.    
    12.    // Get the axis from the left stick (a Vector2 with the left stick's direction)
    13.    var leftStickInputAxis = inputManager.LeftAxis;
    14.    
    15.    // Get the angle between the the direction the model is facing and the input axis vector
    16.    var a = SignedAngle(new Vector3(leftStickInputAxis.x, 0, leftStickInputAxis.y), model.transform.forward);
    17.    
    18.    // Normalize the angle
    19.    if (a < 0)
    20.    {
    21.         a *= -1;
    22.    }
    23.    else
    24.    {
    25.         a = 360 - a;
    26.    }
    27.    
    28.    // Take into consideration the angle of the camera
    29.     a += Camera.main.transform.eulerAngles.y;
    30.    
    31.    var aRad = Mathf.Deg2Rad*a; // degrees to radians
    32.    
    33.    // If there is some form of input, calculate the new axis relative to the rotation of the model
    34.    if (leftStickInputAxis.x != 0 || leftStickInputAxis.y != 0)
    35.    {
    36.         leftStickInputAxis = new Vector2(Mathf.Sin(aRad), Mathf.Cos(aRad));
    37.    }
    38.    
    39.    float xVelocity = 0f, yVelocity = 0f;
    40.    float smoothTime = 0.05f;
    41.    
    42.    // Interpolate between the input axis from the last frame and the new input axis we calculated
    43.     leftStickInputAxis = new Vector2(Mathf.SmoothDamp(lastLeftStickInputAxis.x, leftStickInputAxis.x, ref xVelocity, smoothTime), Mathf.SmoothDamp(lastLeftStickInputAxis.y, leftStickInputAxis.y, ref yVelocity, smoothTime));
    44.    
    45.    // Update the Animator with our values so that the blend tree updates
    46.     animator.SetFloat("Walk", leftStickInputAxis.x);
    47.     animator.SetFloat("Turn", leftStickInputAxis.y);
    48.    
    49.     lastLeftStickInputAxis = leftStickInputAxis;
    50.    
    51.    /* END LOCOMOTION */
    52.    
    53.    
    54.    
    55.    /* START ROTATION */
    56.    
    57.    // Get the axis from the right stick (a Vector2 with the right stick's direction)
    58.    var rightStickInputAxis = inputManager.RightAxis;
    59.    if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0)
    60.    {
    61.        float angle2 = 0;
    62.        if (rightStickInputAxis.x != 0 || rightStickInputAxis.y != 0)
    63.        {
    64.             angle2 = Mathf.Atan2(rightStickInputAxis.x, rightStickInputAxis.y)*Mathf.Rad2Deg;
    65.            if (angle2 < 0)
    66.            {
    67.                 angle2 = 360 + angle2;
    68.            }
    69.        }
    70.        
    71.        // Calculate the new rotation for the model and apply it
    72.        var rotationTo = Quaternion.Euler(0, angle2 + Camera.main.transform.eulerAngles.y, 0);
    73.         model.transform.rotation = Quaternion.Slerp(model.transform.rotation, rotationTo, Time.deltaTime*10);
    74.    }
    75.    
    76.    /* END ROTATION */
    77. }
    78. private float SignedAngle(Vector3 a, Vector3 b)
    79. {
    80.    return Vector3.Angle(a, b) * Mathf.Sign(Vector3.Cross(a, b).y);
    81. }
    82. }
    I THINK that's all of the issues...
     
    NomadKing likes this.
  5. FinlayHanlon

    FinlayHanlon

    Joined:
    Dec 10, 2013
    Posts:
    46