Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How to Resolve Error CS1513

Discussion in 'Scripting' started by DRMMachine, Sep 27, 2022.

  1. DRMMachine


    May 25, 2015

    I am making some simple test code to make random tiles appear upon play. I have looked over this code several times and for the life of me cannot see what is generating all these compiler errors. The first in the list is error CS1513 } expected on line 22.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    5. public class Agog : MonoBehaviour
    6. {
    8.         [SerializeField]
    9.         private Transform wallPrefab = null;
    11.         [SerializeField]
    12.         private Transform wallPrefab2 = null;
    13.          [SerializeField]
    14.         private Transform wallPrefab3 = null;
    16.         [SerializeField]
    17.         private Transform wallPrefab4 = null;
    20.     void Start()
    21.         {
    23.            public int[] array2=new int[4];
    24.            array2[0]=wallPrefab;
    25.            array2[1]=wallPrefab2;
    26.            array2[2]=wallPrefab3;
    27.            array2[3]=wallPrefab4;
    28.            int ycount = Random.Range(1,5);
    29.            int xcount=Random.Range(1,5);
    30.            int a=0;
    31.            int 1choice;
    32.            int 2choice;
    33.            int 3choice;
    34.            int 4choice;
    35.            int 5choice;
    36.            int 6choice;
    37.            int 7choice;
    38.            int 8choice;
    40.            if(ycount==1)
    41.            {
    42.             1choice=array2[Random.Range(0,array2.Length)];
    43.                 Instantiate(1choice, new Vector3(1, 0, 0), Quaternion.identity);
    45.             }
    47.            if(ycount==2)
    48.            {
    49.                2choice= array2[Random.Range(0,array2.Length)];
    50.                 Instantiate(2choice, new Vector3(1, 0, 0), Quaternion.identity);
    51.             }
    53.            if(ycount==3)
    54.            {
    55.                3choice= array2[Random.Range(0,array2.Length)];
    56.                 Instantiate(3choice, new Vector3(1, 0, 0), Quaternion.identity);
    57.              }
    59.          if(ycount==4)
    60.            {
    61.              4choice= array2[Random.Range(0,array2.Length)];
    62.                 Instantiate(4choice, new Vector3(1, 0, 0), Quaternion.identity);
    63.           }
    66.        if(xcount==1)
    67.            {
    68.             5choice= array2[Random.Range(0,array2.Lengt)];
    69.                 Instantiate(5choice, new Vector3(1, 0, 0), Quaternion.identity);
    71.             }
    73.            if(xcount==2)
    74.            {
    75.                6choice=array2[Random.Range(0,array2.Length)];
    76.                 Instantiate(6choice, new Vector3(1, 0, 0), Quaternion.identity);
    77.             }
    79.            if(xcount==3)
    80.            {
    81.                7choice= array2[Random.Range(0,array2.Length)];
    82.                 Instantiate(7choice, new Vector3(1, 0, 0), Quaternion.identity);
    83.              }
    85.          if(xcount==4)
    86.            {
    87.              8choice= array2[Random.Range(0,array2.Length)];
    88.                 Instantiate(8choice, new Vector3(1, 0, 0), Quaternion.identity);
    89.           }
    91.     }
    94. }
  2. mopthrow


    May 8, 2020
    Hi, delete the word public on 23. You can't put access modifiers like public on variables declared in functions. This is because they're only directly accessible to the function they're declared in, so it doesn't make sense to talk about what can access them from the outside the class (which is what public, private etc specify).
    Last edited: Sep 27, 2022
  3. Kurt-Dekker


    Mar 16, 2013
    Where did you get this code?

    Identifiers beginning with numbers won't work...

    You should perhaps start with some basic tutorials...

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.

    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

    Imphenzia / imphenzia - super-basic Unity tutorial:

    Jason Weimann:

    Brackeys super-basic Unity Tutorial series:

    Sebastian Lague Intro to Game Development with Unity and C#: