[c#] "A namespace cannot directly contain members such as fields or methods"

I am trying to use this code for NET.reflector using Reflexil. I am trying to replace code with this:

if(Input.GetKeyDown(KeyCode.Keypad5)) { 
int i = 0; 
Character localPlayer = PlayerClient.GetLocalPlayer().controllable.GetComponent<Character>(); 
foreach (UnityEngine.Object obj2 in UnityEngine.Object.FindObjectsOfType(typeof(LootableObject))) 
{ 
    if (obj2 != null) 
    { 
        i++; 
        LootableObject loot = (LootableObject) obj2; 
        Debug.Log("Loot "+i+": "+loot.transform.position.ToString()); 
        CCMotor ccmotor = localPlayer.ccmotor; 
        if(ccmotor != null && tpPos1 != Vector3.zero) { 
            ccmotor.Teleport(loot.transform.position); 
            Notice.Popup("?", "Teleported to "+loot.name, 1.5f); 
        } 
        break; 
    } 
} 

}

But it gives me an error when I try to compile:

Line: 1 Column: 1 Error Number: CS0116  Error Message: "A namespace does not directly contain members such as fields or methods"

This is Unity code I think. I am not that experienced. Could anyone fix this for me? Or tell me what to do? Thanks!

This question is related to c# button unity3d keycode reflexil

The answer is


The snippet you're showing doesn't seem to be directly responsible for the error.

This is how you can CAUSE the error:

namespace MyNameSpace
{
   int i; <-- THIS NEEDS TO BE INSIDE THE CLASS

   class MyClass
   {
      ...
   }
}

If you don't immediately see what is "outside" the class, this may be due to misplaced or extra closing bracket(s) }.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to button

How do I disable a Button in Flutter? Enable/disable buttons with Angular Disable Button in Angular 2 Wrapping a react-router Link in an html button CSS change button style after click Circle button css How to put a link on a button with bootstrap? What is the hamburger menu icon called and the three vertical dots icon called? React onClick function fires on render Run php function on button click

Examples related to unity3d

Unity Scripts edited in Visual studio don't provide autocomplete not finding android sdk (Unity) Serialize and Deserialize Json and Json Array in Unity How to make the script wait/sleep in a simple way in unity Unity 2d jumping script How to prepare a Unity project for git? "A namespace cannot directly contain members such as fields or methods" How to use Git for Unity3D source control? How to prevent colliders from passing through each other? What Language is Used To Develop Using Unity

Examples related to keycode

"A namespace cannot directly contain members such as fields or methods" Get the value of input text when enter key pressed What are the JavaScript KeyCodes? How to know if .keyup() is a character key (jQuery) Where can I find a list of Mac virtual key codes? Get Character value from KeyCode in JavaScript... then trim Where can I find a list of keyboard keycodes?

Examples related to reflexil

"A namespace cannot directly contain members such as fields or methods"