Error cs1022 type or namespace definition or end of file expected

I'm fairly new to c# and unity and I don't know what this error means, i'm trying to make the floor tilt like in super monkey ball, I know how it all works but I copied and pasted it so to not make

I’m fairly new to c# and unity and I don’t know what this error means, i’m trying to make the floor tilt like in super monkey ball, I know how it all works but I copied and pasted it so to not make mistakes and to save time.

This is the code, please help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Floor_Control : MonoBehaviour{}
{
    public float speed;
    public float max;

    void FixedUpdate()
    {
        //Player Input
        float step = speed * Time.deltaTime;
        float tiltX = -Input.GetAxis("Horizontal") +         Input.GetAxis("Vertical");
        float tiltZ = Input.GetAxis("Horizontal") +     Input.GetAxis("Vertical");
        GetComponent<Rigidbody>().rotation =     Quaternion.RotateTowards(transform.rotation,     Quaternion.Euler(max * tiltZ, 0, max * tiltX), step);
    }
}

asked Jan 15, 2020 at 19:44

Campbell Russell's user avatar

3

Remove the braces after MonoBehaviour «{}». You also don’t have a namespace declaration which may also generate that error message:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TestProgram
{
    public class Floor_Control : MonoBehaviour
    {
        public float speed;
        public float max;

        void FixedUpdate()
        {
            //Player Input
            float step = speed * Time.deltaTime;
            float tiltX = -Input.GetAxis("Horizontal") +         Input.GetAxis("Vertical");
            float tiltZ = Input.GetAxis("Horizontal") +     Input.GetAxis("Vertical");
            GetComponent<Rigidbody>().rotation =     Quaternion.RotateTowards(transform.rotation,     Quaternion.Euler(max * tiltZ, 0, max * tiltX), step);
        }
    }
}

answered Jan 15, 2020 at 20:02

Mark McWhirter's user avatar

Mark McWhirterMark McWhirter

1,1483 gold badges11 silver badges28 bronze badges

1

ошибка CS1022: ожидается определение типа или пространства имен или конец файла

Я создаю приложение для обмена сообщениями для andriod / ios, но я совершенно новичок в c # и работе с сетями, я прошел первые шаги простого руководства по сокетам, чтобы начать работу в сети (https://www.youtube.com/watch?v=KxdOOk6d_I0), но я получаю сообщение об ошибке:

ошибка «CS1022: определение типа или пространства имен или ожидаемый конец файла».

Я предполагаю, что это как-то связано с пространством имен, потому что я новичок в c # и на самом деле не понимаю, что делает пространство имен, но мой компилятор говорит, что ошибок нет (я использую код Visual Studio, если это имеет значение ) но это может быть что-то еще.

Он должен сказать сервер запущен . «или выдать исключение, но это то, что я получаю каждый раз:

[Запуск] моно «C: Users Aidan AppData Roaming Code User cs-script.user cscs.exe» «d:! Информатика !! NEA! Test stuff network server_test program. cs «Ошибка: указанный файл не может быть скомпилирован.

csscript.CompilerException: d:! computer science !! NEA! test stuff network server_test program.cs (7,127): ошибка CS1513:> ожидается d:! computer science !! NEA! test stuff network server_test program.cs (37,1): ошибка CS1022: определение типа или пространства имен или ожидаемый конец файла

at csscript.CSExecutor.ProcessCompilingResult (результаты System.CodeDom.Compiler.CompilerResults, System.CodeDom.Compiler.CompilerParameters compilerParams, синтаксический анализатор CSScriptLibrary.ScriptParser, System.String scriptFileName, дополнительное имя System.String [0], [0]. в: 0 в csscript.CSExecutor.Compile (System.String scriptFileName) [0x0080d] в: 0 в csscript.CSExecutor.ExecuteImpl () [0x005a1] в: 0

[Готово] выход с кодом = 1 через 1,795 секунды

Источник

error CS1022: Type or namespace definition, or end-of-file expected

I’m creating a messaging application for andriod/ios, but I am completely new to c# and networking, I’ve followed the first steps of a simple socket tutorial to get me started in networking (https://www.youtube.com/watch?v=KxdOOk6d_I0) but I get the error:

error «CS1022: Type or namespace definition, or end-of-file expected».

I’m assuming that it has something to do with the namespace because im new to c# and don’t actually understand what the namespace does, but my compiler says there are no errors (I’m using visual studio code if that makes a difference) but it may be something else.

it should say server started. » or throw up an exeption but this is what im getting every time:

[Running] mono «C:UsersAidanAppDataRoamingCodeUsercs-script.usercscs.exe» «d:!computer science!!NEA!test stuffnetworkingserver_testprogram.cs» Error: Specified file could not be compiled.

csscript.CompilerException: d:!computer science!!NEA!test stuffnetworkingserver_testprogram.cs(7,127): error CS1513: > expected d:!computer science!!NEA!test stuffnetworkingserver_testprogram.cs(37,1): error CS1022: Type or namespace definition, or end-of-file expected

at csscript.CSExecutor.ProcessCompilingResult (System.CodeDom.Compiler.CompilerResults results, System.CodeDom.Compiler.CompilerParameters compilerParams, CSScriptLibrary.ScriptParser parser, System.String scriptFileName, System.String assemblyFileName, System.String[] additionalDependencies) [0x00102] in :0 at csscript.CSExecutor.Compile (System.String scriptFileName) [0x0080d] in :0 at csscript.CSExecutor.ExecuteImpl () [0x005a1] in :0

[Done] exited with code=1 in 1.795 seconds

Источник

To add to what Richard has — correctly — said …

In C# everything is part of a class, there is no «global code» or «global methods».
So when you write code like this:

namespace BookListRazor
12  {
13      public class Program
14      {
15          public static void Main(string[] args)
16          {
17              CreateHostBuilder(args).Build().Run();
18          }
19
20          public static IHostBuilder CreateHostBuilder(string[] args) =>
21              Host.CreateDefaultBuilder(args)
22                  .ConfigureWebHostDefaults(webBuilder =>
23                  {
24                      webBuilder.UseStartup<Startup>();
25                  });
26      }
27  }
28
29
30
31
32  var builder = WebApplication.CreateBuilder(args);
33
34  
35  builder.Services.AddRazorPages();

The two close curly brackets on lines 26 and 27 close the Program class and the BookListRazor namespace respectively, and are outside of any class (and indeed namespace).
As such, the lines of code after them won’t compile — they cannot be accessed at all so the compiler refuses to have anything to do with them.

In addition, even if you moved them into the class, they still wouldn’t compile because with the exception of field or property definitions all executable code code must be contained in a method.

I assume that they should actually be a part of the CreateHostBuilder method, but since you have used a short form method definition you would need to change that to a curly bracket form instead:

namespace BookListRazor
    {
    public class Program
        {
        public static void Main(string[] args)
            {
            CreateHostBuilder(args).Build().Run();
            }

        public static IHostBuilder CreateHostBuilder(string[] args)
            {
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());

            var builder = WebApplication.CreateBuilder(args);

            
            builder.Services.AddRazorPages();
            ...
            }
        }
    }

Понравилась статья? Поделить с друзьями:
  • Error cs1022 expected unity
  • Error cs1018 keyword this or base expected
  • Error cs1014 a get or set accessor expected
  • Error cs1012 too many characters in character literal
  • Error cs1011 empty character literal