Search Unity

CS8025: Parsing error

Discussion in 'Scripting' started by GreyMynx, Jan 7, 2016.

  1. GreyMynx

    GreyMynx

    Joined:
    May 4, 2014
    Posts:
    55
    Hello everyone. Right now I am working on a script to select a game object on right click and I'm having an issue with the right click raycasting selection script. If anyone could take a look I'd greatly appreciate it.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RightClickSelector : MonoBehaviour {
    5.  
    6.     GameObject activeObject;
    7.  
    8.     void Update () {
    9.  
    10.         if (Input.GetMouseButtonDown(1)){
    11.             Ray ray = camera.ScreenPointToRay(Input.mousePosition);
    12.             RaycastHit hit;
    13.             if (Physics.Raycast(ray, out hit)){
    14.                  activeObject =(hit.transform.gameObject);
    15.             }
    16.     }
    17. }
    18.  
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    4 {, 3 } ...
     
  3. GreyMynx

    GreyMynx

    Joined:
    May 4, 2014
    Posts:
    55
    I don't understand what you are trying to point out
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you have 4 opening brackets, and 3 closing brackets... short 1 closing bracket

    parsing errors means the syntax is bad, so check the brackets etc.
     
    Last edited: Jan 7, 2016
  5. GreyMynx

    GreyMynx

    Joined:
    May 4, 2014
    Posts:
    55
    I tried that and it still doesn't work. I rephrased the lines and it's still giving the same error.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class RightClickSelect : MonoBehaviour {
    6.  
    7.     void Update(){
    8.         if (Input.GetMouseButtonDown(1)){ // if rightbutton pressed...
    9.             Ray ray = camera.ScreenPointToRay(Input.mousePosition);
    10.             RaycastHit hit;
    11.                  if (Physics.Raycast(ray, out hit)){
    12.                 GameObject activeObject = (hit.transform.gameObject);
    13.             }
    14.                 else
    15.             {
    16.                 GameObject activeObject = null;
    17.  
    18.             }
    19.         }
    20. }
    21.  
     
  6. Ysgramor

    Ysgramor

    Joined:
    Jan 23, 2014
    Posts:
    69
    just add one } in the bottom end, u must ensure that the { must close it with }.
     
  7. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    342
    Doesn't the compiler tell you exactly where and what the problem is?
     
  8. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you've not added another closing bracket, all you've done is add an else clause to the if. COUNT the opening and closing brackets. Also, if you correctly formatted the code you would immediately see the issue.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class TestScript : MonoBehaviour
    7. { // open 1
    8.  
    9.     void Update()
    10.     { // open 2
    11.         if (Input.GetMouseButtonDown(1))
    12.         { // open 3
    13.             Ray ray = camera.ScreenPointToRay(Input.mousePosition);
    14.             RaycastHit hit;
    15.             if (Physics.Raycast(ray, out hit))
    16.             { // open 4
    17.                 GameObject activeObject = (hit.transform.gameObject);
    18.             } // close 4
    19.             else
    20.             { // open 5
    21.                 GameObject activeObject = null;
    22.  
    23.             } // close 5
    24.         } //close 3
    25.     } //close 2
    26.  
    27.     // where is close 1?!?!?
    28.  
    once that syntax error is fixed you'll run into the fact that you've done line 11 incorrectly, should be:

    Code (csharp):
    1.  
    2. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    3.  
    vs at the very least is putting in a red squiggle at the end of the file where the missing bracket is meant to be :rolleyes:
     
  9. GreyMynx

    GreyMynx

    Joined:
    May 4, 2014
    Posts:
    55
    Alright thank you guys I finally got it to work correctly.