Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help fixing a parsing error

Discussion in 'Scripting' started by InsertNameH3re, Apr 20, 2021.

  1. InsertNameH3re

    InsertNameH3re

    Joined:
    Apr 18, 2021
    Posts:
    13
    It says there is an error in: Assets / Scripts / GamePlay.cs (123,17): error CS8025: Parsing error ¿How I can fix it?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GamePlay : MonoBehaviour {
    5.    
    6.     public GameObject[] petList;
    7.     public int maxPetCount = 40;
    8.    
    9.     // An ArrayList for chained pet
    10.     private ArrayList chainedList;
    11.    
    12.     // A place to keep all created pet to, easier management
    13.     private GameObject petHolder;
    14.    
    15.     // Use this for initialization
    16.     void Start () {
    17.        
    18.         // Create the place holder
    19.         petHolder = new GameObject ("Holder");
    20.        
    21.         // Create the list
    22.         chainedList = new ArrayList();
    23.        
    24.         // Move the pet creation to a function, so we can reuse it with
    25.         // spawning different number
    26.         Respawn (maxPetCount);
    27.     }
    28.    
    29.     // Function to create pets
    30.     void Respawn (int count) {
    31.         for (int i=0; i<count; i++) {
    32.             GameObject instance = Instantiate (petList[Random.Range(0, petList.Length)], new Vector3 (Random.Range(-2.6f, 2.6f), 7.0f, -1.0f), Quaternion.identity) as GameObject;
    33.            
    34.             // put the newly pet as the child of petHolder
    35.             instance.transform.SetParent(petHolder.transform);
    36.         }
    37.     }
    38.     // Update is called once per frame
    39.     void Update () {
    40.        
    41.         if (Input.GetMouseButtonDown (0)) {
    42.             // simulate touch began
    43.            
    44.             Vector3 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    45.             RaycastHit2D hit = Physics2D.Raycast (p, Vector2.zero);
    46.             if (hit.collider != null) {
    47.                 if (hit.collider.tag == "Pet") {
    48.                     Pet pet = hit.collider.GetComponent<Pet> ();
    49.                     // Add the pet to the chain
    50.                     chainedList.Add (pet);
    51.                     // Make it selected
    52.                     pet.SetSelected (true);
    53.                 }
    54.             }
    55.         }
    56.        
    57.         if (Input.GetMouseButtonUp (0)) {
    58.             // simulate touch ended
    59.            
    60.             // Only destroy pets in the chain with count > 2
    61.             if (chainedList.Count > 2) {
    62.                 // Loop for every pet in the chain
    63.                 foreach (Pet pet in chainedList) {
    64.                     // Destroy it
    65.                     Destroy (pet.gameObject);
    66.                 }
    67.                 // Call respawn function to generate new pets
    68.                 Respawn (chainedList.Count);
    69.             } else {
    70.                 // Chain count less than 3, just make the last pet unselected
    71.                 SetChainedLastPetSelected (false);
    72.             }
    73.            
    74.             // Clear the chain list
    75.             chainedList.Clear ();
    76.         }
    77.        
    78.         if (Input.GetMouseButton (0) && chainedList.Count > 0) {
    79.             // simulate touch moved
    80.             Vector3 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    81.             RaycastHit2D hit = Physics2D.Raycast (p, Vector2.zero);
    82.            
    83.             if (hit.collider != null) {
    84.                 if (hit.collider.tag == "Pet") {
    85.                     Pet pet = hit.collider.GetComponent<Pet> ();
    86.                    
    87.                     // Check if this pet already inside the chain?
    88.                     if (!chainedList.Contains(pet)) {
    89.                         // Not inside the chain, is it valid to be chained?
    90.                         if (GetLastPetInChain ().Validate (pet)) {
    91.                             // Yes, make the last chained pet unselected
    92.                             SetChainedLastPetSelected (false);
    93.                             // Add to the chain
    94.                             chainedList.Add (pet);
    95.                             // Make it selected
    96.                             pet.SetSelected (true);
    97.                         }
    98.                     } else {
    99.                         // This pet is inside our chain, what is the index?
    100.                         int index = chainedList.LastIndexOf (pet);
    101.                         // Second last?
    102.                         if (index == chainedList.Count - 2) {
    103.                             // Backward to second last pet, unselect the last pet
    104.                             SetChainedLastPetSelected (false);
    105.                             // Remove the last one
    106.                             chainedList.RemoveAt(chainedList.Count-1);
    107.                             // Make the last pet selected
    108.                             SetChainedLastPetSelected (true);
    109.                         }
    110.                     }
    111.                 }
    112.             }
    113.         }      
    114.  
    115.         // Process at every frame no matter there are pets in the chain
    116.         foreach (Pet pet in petHolder.GetComponentsInChildren<Pet>()) {
    117.             pet.SetHighlight (false);
    118.         }
    119.        
    120.         // Highlight pet if there is a pet in the chain
    121.         if (chainedList.Count > 0) {
    122.             HighlightValidPet (GetLastPetInChain());
    123.         }
     
  2. I guess it would help if you finish your code: close the Update method with } and then the class too, also with a }.
    But you may be missing more things, it's hard to tell, your file is cut in half.
     
    Joe-Censored and BenniKo like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    Everything you need is in that line... everything.

    The important parts of an error message are:
    - the description of the error itself
    - the file it occurred in
    - the line number and character position.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly.

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Is this the entire script, or did you just paste part of it? Because you're missing the end of the script.