Cs1002 unity ошибка

enter image description hereI have followed the tutorial on how to make a game of Brackeys from YouTube and I’m stuck on video no. 7 and I can’t figure out how to resolve the problem. Please help.

link to tutorial

The code is at 7:36

using UnityEngine;
using UnityEngine UI;

public class Score : MonoBehaviour
{
       public Transform player;
       public Text scoreText;

       void Update()
       {
            scoreText.text = player.position.z.ToString("0");
        }
}

asked May 12, 2020 at 4:31

Tanmy Modi's user avatar

4

First, check the second line of your code. using UnityEngine UI; appears to missing a period between UnityEngine and UI. I believe this is the core of your problem and is causing the other two errors to pop up. The line should be using UnityEngine.UI;.

Regardless, here is an explanation on how to figure out the route of a problem like this.

Please see the following two links for information regarding your two error codes. Remember that these are always available via a quick Google search:

  • CS1002: this error signifies that you are missing a semicolon (;). I C#, a semicolon is required at the end of almost all lines. Looking at your code, the missing semicolon is not within this specific code block, so it must be elsewhere in your code. To find it, the easiest method is ton go to the Unity Console Window and double click the error line or look for the script location and line number in the message. Either of these should bring you close to where the missing semicolon is.
  • CS0116: This error signifies the a namespace that contains something other than a class, struct, or other namespace. This means that the structure of your code is flawed. Again go to to the error and see if you can find the script that this is contained in. Then review the structure and ensure that there aren’t any areas where a something like a method falls outside of your class (this is common and would mean that you placed a method directly into a namespace, which will result in CS0116.

Hope this helps!

Edit: thinking a minute more on the logic here and it’s 100% the second line. Imagine how the compiler would interpret this. What it really see’s when you miss that period is «two lines»

using UnityEngine
UI;

So it’s looking at this and saying two things:

  1. You’re missing a semicolon after using UnityEngine
  2. You’re to do something in the namespace area before your class that is not allowed

Kinda interesting when you think about why it is telling you that you have both of those errors.

answered May 12, 2020 at 6:22

Jee's user avatar

JeeJee

9691 gold badge7 silver badges26 bronze badges

1

The error is in the second line of your code:

using UnityEngine;
using UnityEngine UI;

Should be changed to:

using UnityEngine;
using UnityEngine.UI;

You need a period to access another Namespace within the UnityEngine Namespace.

answered Jul 22, 2020 at 18:24

Arcanum Astronaut's user avatar

Ошибка CS1002 является одной из наиболее распространенных в Unity. Она происходит, когда вы забыли поставить точку с запятой (;) в коде.

Что такое ошибка CS1002?

Ошибка CS1002 означает, что компилятор C# не смог распознать конец выражения. Это может произойти, если вы забыли поставить точку с запятой в конце оператора.

Как исправить ошибку CS1002?

Если вы столкнулись с ошибкой CS1002, вам нужно проверить ваш код на предмет недостающих точек с запятой. Если у вас есть несколько операторов на одной строке, попробуйте разделить их на отдельные строки.

Например:

// Неправильно
int x = 5 int y = 3;

// Правильно
int x = 5;
int y = 3;

Если проблема не решается, попробуйте проверить другие ошибки в вашем коде. В некоторых случаях, если у вас есть другая ошибка, это может привести к ошибке CS1002.

Заключение

Ошибка CS1002 является довольно частой ошибкой, но ее легко исправить, как только вы поймете, что вызвало проблему. Убедитесь, что вы всегда ставите точки с запятой в конце операторов и проверяете свой код на другие ошибки, прежде чем продолжать работу в Unity.

Recommended

  • 1. Download ASR Pro
  • 2. Follow the on-screen instructions to run a scan
  • 3. Restart your computer and wait for it to finish running the scan, then follow the on-screen instructions again to remove any viruses found by scanning your computer with ASR Pro
  • Speed up your PC today with this easy-to-use download.

    Over the past few days, some of our users have reported error cs1002.

    g.The compiler encountered an expired semicolon. When using C #, a semicolon is required at the end of each statement. An instruction can be multiple lines.

    g.

    Recommended

    Is your PC running slow? Do you have problems starting up Windows? Don’t despair! ASR Pro is the solution for you. This powerful and easy-to-use tool will diagnose and repair your PC, increasing system performance, optimizing memory, and improving security in the process. So don’t wait — download ASR Pro today!

  • 1. Download ASR Pro
  • 2. Follow the on-screen instructions to run a scan
  • 3. Restart your computer and wait for it to finish running the scan, then follow the on-screen instructions again to remove any viruses found by scanning your computer with ASR Pro
  • Attempt to create a new instance of each MortgageData object along the way.

    What does the stack overflow error cs1002 mean?

    : (- Stack overflow error CS1002 :; Expected – I have a semicolon .: (I am trying to create a new instance of the “MortgageData” object. I keep getting the error CS1002 :: Expected with the class name underlined in red after the original.

      instance name of class name = new class name (arg1, arg2, arg3, arg4); 

      MortgageData is something equal to MortgageData (ID, Principal, Apr, Deadline); 

    Keep readingError CS1002:. Expected with the class name below, underlined in red after the new one. I am using Visual Studio 2008.

    Learn More:

    This error usually occurs in C # code where there are fewer semicolons or fewer parentheses on the master page, causing the compiler to crash. Make sure the C # method renders correctly on the page.
    I did this because @ code is missing a check mark in the foreground sheet. Add parentheses to solve the problem.

    Hello, I just started learning Unity and C #, but I get this error: Assets StandardAssets Characters FirstPersonCharacter Scripts PLAYER.cs (18,27): error CS1002 :; expected

    Compilation

    Description:An error occurred while collecting a resource required to deliver this request. Review the following error details and modify your main source code accordingly.

    How do I fix unity error cs1002 expected?

    Compiler Error CS1002: Frequency:; expected

    Source error:

    Is there an error cs1002 expected in Unity Forum?

    g.Express your opinion. Do our analysis and let us know. Not open to other answers. Can't find: and. Max_tallboi loves it Click to view Please use code tags on this page when posting code. NicolasIT likes the idea. Read the error message carefully. semicolon; expected.

     [No matching tutorial lines] 

    Source file: c: WINDOWS Microsoft.NET Framework v2.0.50727 Temporary ASP.NET files mahall 61b28278 4470085c App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs Line: 1551 Warning
    error cs1002

    Compiler messages:

    Warning: CS0168: variable ‘_tax’ is declared but rarely used
    Source error:

    c: Inetpub wwwroot Mahall Forms AmountSettlement.aspx.cs

     Line 20: protected space text field Maintance_TextChanged (object sender, EventArgs e)Line 21: Class = ""> line {
    

    Warning: CS0168: variable is expressed in the form «_nettotal» but never used
    Source error:

    c: Inetpub wwwroot Mahall Forms AmountSettlement.aspx.cs

    error cs1002

     Line 20: Blanket void textboxMaintance_TextChanged (object sender, EventArgs e)Line 18: Class = ""> line {
    

    How do I fix cs0246 error?

    There are two solutions that can cause this error. First — stimprove the namespace name to deal with the existing one. The second option is to fix the custom namespace you created.

    Show verbose com outputpiler:

    Id = compilerOutputDiv

     C:  WINDOWS  system32> "C:  WINDOWS  Microsoft.NET  Framework  v3.5  csc.exe" / t: library / utf8output / R: "C:  WINDOWS  assembly  GAC_MSIL  System .IdentityModel  3.0.0.0__b77a5c561934e089  System.IdentityModel.dll "/R:"C:WINDOWSassemblyGAC_MSILSystem.Drawing2.0.0.0__b03f5f7f11d50a3aSystem.Drawing.dll"  Build WINDOWS " " WMSSystem .Web.Extensions  3.5.0.0__31bf3856ad364e35  System.Web.Extensions.dll" /R:"C:WINDOWSassemblyGAC_MSILSystem.WorkflowServices3.5.0.0__31bf3856ad364e35System .WorkflowServices Dll "/:":  WINDOWS  assembly  GAC_32  System.EnterpriseServices  2.0.0.0__b03f5f7f11d50a3a  System.EnterpriseServices.dll "/R:"C:WINDOWSassemblyGAC_MSILSystem.Data.DataSetSetExtensions  .0.0__b77a5c561934e089  System.Data.DataSetExtensions.dll "/R:"C:WINDOWSassemblyGAC_MSILSystem.Xml2.0.0.0__b77a5c561934e089System.Xml.dll" / R: "C:  WINDOWS.  assembly  GAC_MSIL  System.Web.Mobile  2.0.0.0__b03f5f7f11d50a3a  System.W eb.Mobile.dll "/ R:" C:  WINDOWS  assembly  GAC_MSIL  System  2.0.0.0__b77 a5c56 1934e089  System.dll " /R:"C:WINDOWSassemblyGAC_MSILSystem.Xml.Linq  3.5.0.0__b77a5c561934e089  System.Xml.Linq.dll "/ R:" C:  WINDOWS  Microsoft. NET  Framework  v2.0.50727  mscorlib.dll "/R:"C:WINDOWSMicrosoft.NETFrameworkv2.0.50727 ASP.NET Temporary Files  mahall  61b28278  4470085c  App_Web_jphxmu7c.dll" / R: "C:  WINDOWS  assembly  GAC_32  System.Data  2.0.0.0__b77a5c561934e089  System.Data.dll "/ R:" C:  WINDOWS  assembly  GAC_MSIL  System.ServiceModel.Web  3.5.0.0__31bf3856ad364e35  System. ServiceModel.Web.dll "/R:"C:WINDOWSassemblyGAC_MSILSystem.ServiceModel3.0.0.0__b77a5c561934e089System.ServiceModel.dll" /R:"C:WINDOWSassemblyGAC_MSILSystem.Coniguration  2.0.0.0__b03f5f7f11d50a3a System.Configuration.dll "/R:"C:WINDOWSassemblyGAC_MSILSystem.Runtime.Serialization3.0.0.0__b77a5c561934e089System.Runtime.Serialization.dll" / R: "C:  WINDOWS  assembly  GAC_MSIL  System.Core  3.5.0.0__b77a5c561934e089  System.Core.dll "/ R:" C:  WINDOWS  assembly  GAC_MSIL  System.Web.Services  2.0.0.0__b03f5f7f11d50a3ab  S ystem.Web .Services.dll "/ R: "C:  WINDOWS  assembly  GAC_32  System.Web  2.0.0.0__b03f5f7f11d50a3a  System.Web.dll" /out:"C:WINDOWSMicrosoft.NETFrameworkv2. 0.50727  Temporary ASP.NET files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.dll "/ debug- / optimize + / w: 4 / nowarn: 1659; 1699; 1701 / warnaserror-" C:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  ASP.NET Temporary Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs "" C:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  ASP.NET Temporary Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.1.cs "" C:  WINDOWS  Microsoft. NET  Framework  v2.0.50727  Temporary ASP.NET Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.2.cs "Microsoft (R) Visual C # 2008 Compiler version 3.5.30729.1for Microsoft (R) .NET Framework version 3.5Copyright (C) Microsoft Corporation. All rights reserved.c:  Inetpub  wwwroot  Mahall  Forms  AmountSettlement.aspx.cs (22.60): Warning CS0168: flexible '_tax' declared but usedc:  Inetpub  wwwroot  Mahall  Forms  AmountSettlement.aspx.cs (22,74): Warning CS0168: variable '_nettotal' is probably declared but never usedc:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  ASP.NET Temporary Files  mahall  61b28278 4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs (1551,17): Error CS1002 :; expectedc:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  ASP.NET Temporary Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs (1551,17): CS1525 Error: Invalid The range of expression '.'c:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  ASP.NET Temporary Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs (1551.18): CS1002 Error: - - expectedc:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  ASP.NET Temporary Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs (1559.17): Error CS1002 :. expectedc:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  Temporary ASP.NET Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs (1559.17): CS1525 error: gesture concept is invalid '.'c:  WINDOWS  Microsoft.NET  Framework  v2.0.50727  ASP.NET Temporary Files  mahall  61b28278  4470085c  App_Web_amountsettlement.aspx.ba00be51.jfgzpl-k.0.cs (1559.18): error CS1002 :; color = "# c0c0c0" expected


    blskv1

    I know this is an old post, but thought it might be worth adding this concept. I got this error after adding another javascript function to our own .aspx page. I have checked my code and have checked most of all and I may not have found the problem. This is a pretty straightforward solution. I made a copy my code, useEditing .aspx and .aspx.cs articles and removing the entire page from the draft article. Then I recreated the designed page and pasted my code backwards. This is an important note: I didn’t usually copy <@% Page …%>, I asked Visual Studio to recreate it. think My hidden problem was the signs, but I also can’t be sure.

    After correcting this process, the project skipped without errors. I just thought I’d leave this for anyone as annoyed as me.

    Good programming!

    B.

    blskv1

    I know there is an old post here, but I thought I should add this information. I got this error after adding a javascript function to my husband and my .aspx page. I have checked and duplicated most of my code and may not be able to find the problem. This can be a pretty simple copy solution from my code for .aspx and .aspx.cs posts and removed the whole page from part of my project. Then I recreated the created page and added support for my code in <@% Page …%>, in particular, I have Visual Studio to emulate this. think My hidden probesThe lema was in the signs, but I still can’t say for sure.

    What is error cs1026?

    Incomplete statement found. A common cause of this error is the output of a statement instead of an expression from an inline expression in an ASP.NET document. For example, the following is incorrect: copy of ASP.NET (C #).

    After this fix, the project worked without errors. I just thought I would throw it to anyone as worried as I am.

    Good programming!

    B.

    Speed up your PC today with this easy-to-use download.

    How do I fix error CS0117?

    To fix standard error CS0117, remove the links you want to create that are not normally defined in the base classes.

    How do I fix cs0246 error?

    There are only two solutions to this error. The main reason is to correct the name as well as the namespace to match the pre-existing «why». The second is to fix the custom namespace that was created.

    What is error cs1003?

    What a mistake you missed; somewhere for your code. However, you obviously do not have it; corn . There is really nothing special to look out for in the future, follow the instructions immediately and try to get this syntax error.

    New issue

    Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

    By clicking “Sign up for GitHub”, you agree to our terms of service and
    privacy statement. We’ll occasionally send you account related emails.

    Already on GitHub?
    Sign in
    to your account

    Closed

    chegor0 opened this issue

    Jul 15, 2021

    · 2 comments

    Labels

    area-tutorials

    Issues related to getting started tutorials

    needs-more-info

    Not enough information has been provided. Please share more detail as requested.

    Comments

    @chegor0

    // Unity said that i have a 1002 error when i created
    // public void CompleteLevel () and Debug.Log(«LEVEL WON!»);

    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class GameManager : MonoBehaviour {

    bool gameHasEnded = false;
    
    public float restartDelay = 1f
    
    public void CompleteLevel ()
    {
        Debug.Log("LEVEL WON!");
    }
    
    public void EndGame () 
    {
        if (gameHasEnded == false) 
        {
            gameHasEnded = true;
            Debug.Log("GAME OVER");
            Invoke("Restart", restartDelay);
        }
    }
    
    void Restart () 
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
    

    }

    @wfurt

    There should be ‘;’ after ‘1f’. the compiler gives you the line (8) and line position (65) where this should go.
    Seems like you did not put in whole file so the numbering seems off in example above.

    @no-response

    This issue has been automatically closed due to no response from the original author. Please feel free to reopen it if you have more information that can help us investigate the issue further.

    Labels

    area-tutorials

    Issues related to getting started tutorials

    needs-more-info

    Not enough information has been provided. Please share more detail as requested.

    2 participants

    @wfurt

    @chegor0

    When you have a number of errors in the same sourcecode file, then it’s usually a good idea to fix them from top to bottom, because fixing one error might remove or change the errors below it. So I copied your code to a new file in Visual Studio and went through the errors from top to bottom.


    The first error is very straight forward: A semicolon is expected on line 1, position 25. So just add a semicolon after the very first line:

    using System.Collections;
    

    Funny thing: Visual Studio now displays that line in gray, which tells us that there isn’t actually anything in this file which requires this using-declaration. So we could actually just as well remove it altogether.


    Then you are apparently trying to create two MonoBehaviours in one sourcecode file: BRS_ChangeCircle and Score. This won’t work. The C# language does allow you to have multiple classes in one sourcecode file, but Unity requires a separate file for each MonoBehaviour in order to allow you to assign them to GameObject’s. And even if you would want to create a class inlined in another (which you might want to do from time to time, just not with a MonoBehaviour), then the using-declarations required by the inner class need to be on top of the whole file. So remove this part and put it into a new file Score.cs:

    using UnityEngine;
    using System.Collections;
     
    public class Score : MonoBehaviour {
    
        int score = 0;
    
        void OnGUI() {
            guiText.text = "Score: " + score;
        }
    
    }
    

    There is also another problem with this piece of code, and that that there is no variable guiText in that script. It is likely supposed to be a public UnityEngine.UI.Text or public TMPro.TextMeshPro.


    Next error is this line:

    public List<int> ZoneTimes;
    

    This one is simple, and Visual Studio already provides an auto-correction. You forgot to add using System.Collections.Generic; to the very top of the script. This package is required for the class List.


    Then there are just two errors remaining, which are related to the class WorldCircle being unknown. This is not a Unity or C# standard class, so I assume it’s another class from your project. So if you have that class in your project, you shouldn’t get that error.


    Conclusion: It looks as if you copied a very long script written by someone else to your project, and then you tried to modify it by adding code you saw in some YouTube tutorial without really understanding what you were doing.

    It’s hard to get anywhere in Unity when you don’t have at least a basic understanding of the C# language and how to interpret its error messages. If my impression is correct, then I would really recommend to do a basic, technology-neutral C# tutorial first.

    Понравилась статья? Поделить с друзьями:

    Не пропустите эти материалы по теме:

  • Яндекс еда ошибка привязки карты
  • Cs0297c ошибка e98
  • Crysis 3 ошибка msvcr100 dll
  • Crysis 3 ошибка fatal error
  • Crysis 3 не запускается ошибка 0xc0000906

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии