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
  3. Dismiss Notice

Other Assets\Clicker.cs(128,1): error CS1022: Type or namespace definition, or end-of-file expected Help

Discussion in 'Scripting' started by Cheloweck12, May 27, 2024.

  1. Cheloweck12

    Cheloweck12

    Joined:
    Dec 29, 2023
    Posts:
    1
    I wrote a script and Unity says errors
    Assets\Clicker.cs(128,1): error CS1022: Type or namespace definition, or end-of-file expected
    Assets\Clicker.cs(127,6): error CS1022: Type or namespace definition, or end-of-file expected
    Assets\Clicker.cs(122,7): error CS1513: } expected
    Assets\Clicker.cs(120,23): error CS1513: } expected
    Assets\Clicker.cs(120,23): error CS1514: { expected
    and a bunch of other errors

    here is the script, thanks in advance

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System;
    4.  
    5. public class Clicker : MonoBehaviour
    6. {
    7. [SerializeField] private int Score;
    8. public int[] CostInt;
    9. private int ClickScore = 1;
    10.  
    11. public int[] CostBonus;
    12.  
    13. public GameObject ShopPan;
    14. public GameObject BonusPan;
    15.  
    16. public Text[] CostText; // Исправлено название переменной с `CotText` на `CostText`
    17. public Text ScoreText;
    18.  
    19. private void Start()
    20.     {
    21.         StartCorouline(BonusShop());
    22.     }
    23. }
    24.  
    25. private Save sv = new Save();
    26.  
    27. private void Avake()
    28. {
    29. if(PlayerPrefs.HasKey("SV"));
    30. {
    31. sv = JsonUtility.FromJson<Save>(PlayerPrefs.GetString("SV"));
    32. ClickScore = sv.ClickScore;
    33. for(int i = 0; i < 1; i++)
    34. {
    35. CostBonus[i] = sv.CostBonus[i];
    36. }
    37.  
    38. for(int i = 0; i < 2; i++)
    39. {
    40. CostBonus[i] = sv.CostInt int[i];
    41. }
    42.  
    43. PlayerPrefs.SetString("SV",JsonUtility.ToJson(sv));
    44. CostText[i] = sv.CostInt[i] + "$";
    45. }
    46. }
    47. }
    48.  
    49. public void OnClickButton()
    50. {
    51. Score += ClickScore;
    52. }
    53.  
    54. private void Update()
    55. {
    56. ScoreText.text = Score + "$";
    57. }
    58.  
    59. public void ShowAndHideShopPan()
    60. {
    61. ShopPan.SetActive(!ShopPan.activeSelf);
    62. }
    63.  
    64. public void ShowAndHideBonusPan()
    65. {
    66. BonusPan.SetActive(!BonusPan.activeSelf);
    67. }
    68.  
    69. public void OnClickBuyLevel()
    70. {
    71. if (Score >= CostInt[0])
    72. {
    73. Score -= CostInt[0]; // Вычитаем стоимость уровня из счета
    74. CostInt[0] *= 2; // Увеличиваем стоимость для следующего уровня
    75. ClickScore *= 2;
    76. CostText[0].text = CostInt[0] + "$";
    77. }
    78. }
    79.  
    80. public void OnClickBuyBonusShop()
    81. {
    82. if (Score >= CostInt[1])
    83. {
    84. Score -= CostInt[1]; // Вычитаем стоимость уровня из счета
    85. CostInt[1] *= 2;
    86. CostBonus[0] += 2;
    87. CostText[1].text = CostInt[1] + "$";
    88. }
    89. }
    90. IEnumerator BonusShop()
    91. {
    92.     while(true)
    93.     {
    94.     Score += CostBonus [0];
    95.     yield return new WaitForSeconds(1);
    96. }
    97.  
    98. private void OnApplicationQuit()
    99. {
    100. sv.Score = Score;
    101. sv.ClickScore = ClickScore;
    102. sv.CostBonus = new int[1];
    103. sv.CostInt = new int[2];
    104.  
    105. for(int i = 0; i < 1; i++)
    106. {
    107. sv.CostBonus[i] = CostBonus[i];
    108. }
    109.  
    110. for(int i = 0; i < 2; i++)
    111. {
    112. sv.CostBonus[i] = CostInt int[i];
    113. }
    114.  
    115. PlayerPrefs.SetString("SV",JsonUtility.ToJson(sv));
    116. }
    117.  
    118. [SerializeField]
    119.  
    120. public class SetActive;
    121.  
    122.      {
    123.          public int Score;
    124.          public int ClickScore;
    125.          public int[] CostInt;
    126.          public int[] CostBonus;
    127.      }
    128. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,371
    You're making typing mistakes. For instance you're missing various braces
    { and }
    .

    For instance, the BonusShop() coroutine is clearly wrong. You can see it isn't complete. If you cannot see that, go look at ANY other coroutine or function example.

    You can fix your own typing mistakes. Here's how:

    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? Are you structuring the syntax correctly? Look for examples!

    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.

    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.
     
  3. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    692
    You didn't type all this code into your editor right? It hasn't complied in a very long time from the looks of it.

    Here is what you do. Create a new file with a new class, name it Clicker2 for now. Slowly copy a few lines at a time from the broken code into the new one. Start simply with code you can read and understand (the property definitions for instance). Keep an eye open for when the code fails to compile.

    When you have eliminated the errors replace the old code with the new code and delete the Clicker2 file.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,691
    You have fields and methods that are outside of the class definition. If you have a proper code editor it should have started throwing red squigglies everywhere once you started to do that.
     
    Bunny83 likes this.