Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug another problem with ; expected

Discussion in 'Scripting' started by Sindaga, Aug 17, 2023.

  1. Sindaga

    Sindaga

    Joined:
    Feb 14, 2023
    Posts:
    15
    error:
    Assets\Donut.cs(19,76): error CS1002: ; expected

    script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Donut : MonoBehaviour
    6. {
    7.     public float speed;
    8.     Vector3 targetPos;
    9.  
    10.     public GameObject ways;
    11.     public Transform[] wayPoints;
    12.     int pointIndex;
    13.     int pointCount;
    14.     int direction = 1;
    15.  
    16.     private void Awake()
    17.     {
    18.         wayPoints = new Transform[ways.transform.childCount];
    19.         for (int i = 0; i < ways.transform.GetChild(i).gameObject.transform)
    20.         {
    21.             wayPoints[i] = ways.transform.GetChild(i).gameObject.transform;
    22.         }
    23.     }
    24.  
    25.     private void Start()
    26.     {
    27.         pointCount = wayPoints.Lenght;
    28.         pointIndex = 1;
    29.         targetPos = wayPoints[pointIndex].transform.position;
    30.     }
    31.  
    32.     private void Update()
    33.     {
    34.         var step = speed * Time.deltaTime;
    35.         transform.position = Vector3.MoveTorwards(transform.position, targetPos, step);
    36.  
    37.         if (transform.position == targetPos)
    38.         {
    39.             NextPoint();
    40.         }
    41.     }
    42.  
    43.     void NextPoint()
    44.     {
    45.         if (pointIndex == pointCount - 1)
    46.         {
    47.              direction = -1;
    48.         }
    49.  
    50.         if (pointIndex == 0)
    51.         {
    52.             direction = 1;
    53.         }
    54.  
    55.         pointIndex += direction;
    56.         targetPos = wayPoints[pointIndex].transform.position;
    57.     }
    58.  
    59.  
    60.  
    61.  
    62.  
    63.  
    64.  
    65.  
    66.  
    67.  
    68.  
    69.  
    70.  
    71. }
    72.  
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,833
    This is a scripting issue, not a 2D issue.

    The error message is pretty clear: it expects a semicolon (;) in this context. The (19,76) part is telling you what line and column it got confused.

    Line 19 starts your loop. A "for loop" syntax is like this:

    Code (CSharp):
    1. for (
    2.         <initialization> ;
    3.         <condition> ;
    4.         <step>
    5.       )
    6. {
    7.       <statements>
    8. }
    You only gave the <initialization> and <condition> parts, all three need to be there.
     
    Yoreki and Ryiah like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    Nothing special here, you're just making typing mistakes. Don't do that, you will be required to fix them all.

    Here is how you can get started fixing your own errors:

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Please don't post syntax typos on the 2D forum. Either use the Scripting or Getting Started forums. Also, please don't use tags that are nothing to do with the post; they're used by devs to find post topics. I'll move your post for you and remove the tag.

    If you have a post that discusses 2D feature then feel free to post here.

    Thanks.