Search Unity

Multiple Errors in code but doesn't shot up in IDE

Discussion in 'Scripting' started by Handzeepje, May 6, 2020.

  1. Handzeepje

    Handzeepje

    Joined:
    May 3, 2020
    Posts:
    1
    So in Unity, I get these errors: (CS1002 x3, CS1513, CS1525) After a hour of looking and testing I still can't find where the problem is since it does not show up in IDE. In my IDE (Ride from JetBrains) it builds fine without any errors. here is my code:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CameraCollision : MonoBehaviour
    4. {
    5.     public float minDistance;
    6.     public float maxDistance;
    7.     public float smooth;
    8.     private Vector3 dollyDir;
    9.     public Vector3 dollyDirAdjusted;
    10.     public float distance;
    11.  
    12.     public CameraCollision()
    13.     {
    14.         base.ector();
    15.     }
    16.  
    17.     private void Awake()
    18.     {
    19.         Vector3 localPosition1 = ((Component)this).get_transform().get_localPosition();
    20.         this.dollyDir = (Vector3) (localPosition1).get_normalized();
    21.         Vector3 localPosition2 = ((Component)this).get_transform().get_localPosition();
    22.         this.distance = (Vector3) (localPosition2).get_magnitude();
    23.     }
    24.  
    25.     private void Update()
    26.     {
    27.         RaycastHit raycastHit;
    28.         this.distance = ()Physics.Linecast(((Component)this)).get_transform().get_parent().get_position(), ((Component)this).get_transform().get_parent().TransformPoint(Vector3.op_Multiply(this.dollyDir, this.maxDistance)), (raycastHit) ? this.maxDistance : Mathf.Clamp(((RaycastHit) (raycastHit).get_distance() * 0.87f, this.minDistance, this.maxDistance));
    29.         ((Component)this).get_transform().set_localPosition(Vector3.Lerp(((Component)this).get_transform().get_localPosition(), Vector3.op_Multiply(this.dollyDir, this.distance), Time.get_deltaTime() * this.smooth));
    30.     }
    31. }
    32.  

    Also in my other code, I don't seem to find the problem (CS1026)

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CameraFollow : MonoBehaviour
    4. {
    5.     public float CameraMoveSpeed;
    6.     public GameObject CameraFollowObj;
    7.     private Vector3 FollowPOS;
    8.     public float clampAngle;
    9.     public float inputSensitivity;
    10.     public GameObject CameraObj;
    11.     public GameObject PlayerObj;
    12.     public float camDistanceXToPlayer;
    13.     public float camDistanceYToPlayer;
    14.     public float camDistanceZToPlayer;
    15.     public float mouseX;
    16.     public float mouseY;
    17.     public float finalInputX;
    18.     public float finalInputZ;
    19.     public float smoothX;
    20.     public float smoothY;
    21.     private float rotY;
    22.     private float rotX;
    23.  
    24.     public CameraFollow()
    25.     {
    26.         base.ector();
    27.     }
    28.  
    29.     private void Start()
    30.     {
    31.         Quaternion localRotation = ((Component)this).get_transform().get_localRotation();
    32.         Vector3 eulerAngles = ((Quaternion) (localRotation).get_eulerAngles());
    33.         this.rotY = (float)eulerAngles.y;
    34.         this.rotX = (float)eulerAngles.x;
    35.         Cursor.set_lockState((CursorLockMode)1);
    36.         Cursor.set_visible(false);
    37.     }
    38.  
    39.     private void Update()
    40.     {
    41.         float axis1 = Input.GetAxis("Horizontal");
    42.         float axis2 = Input.GetAxis("Vertical");
    43.         this.mouseX = Input.GetAxis("Mouse X");
    44.         this.mouseY = Input.GetAxis("Mouse Y");
    45.         this.finalInputX = axis1 + this.mouseX;
    46.         this.finalInputZ = axis2 + this.mouseY;
    47.         this.rotY += this.finalInputX * this.inputSensitivity * Time.get_deltaTime();
    48.         this.rotX += this.finalInputZ * this.inputSensitivity * Time.get_deltaTime();
    49.         this.rotX = Mathf.Clamp(this.rotX, -this.clampAngle, this.clampAngle);
    50.         ((Component)this).get_transform().set_rotation(Quaternion.Euler(this.rotX, this.rotY, 0.0f));
    51.     }
    52.  
    53.     private void LateUpdate()
    54.     {
    55.         this.CameraUpdater();
    56.     }
    57.  
    58.     private void CameraUpdater()
    59.     {
    60.         ((Component)this).get_transform().set_position(Vector3.MoveTowards(((Component)this).get_transform().get_position()), this.CameraFollowObj.get_transform().get_position(), (this.CameraMoveSpeed * (Time.get_deltaTime()));
    61.     }
    62. }
    63.  
    64.  
     

    Attached Files:

  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    The errors tell you the line numbers. In CameraCollision look at line 28. You have a stray "()" at the start of the right-hand expression.

    As for CameraFollow the error is on line 60, somewhere in that convoluted mess of an expression. My advice is to break that line up into multiple lines. It's impossible to read and understand what it is doing when the line is that long. You're missing a closing parenthesis somewhere in that line.

    Again, let me stress - the reason it's so hard for you to find your error is because you have so much going on in one line in both of these files. You don't get any bonus points for putting a lot of logic in a single line, you just get confusion.
     
    matkoniecz likes this.