89

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!

derHugo
  • 83,094
  • 9
  • 75
  • 115
user3204732
  • 903
  • 1
  • 6
  • 4

1 Answers1

165

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) }.

G. Stoynev
  • 7,389
  • 6
  • 38
  • 49
  • 2
    Thanks, just needed a tip whether it was the code or not. Thanks! – user3204732 Jan 17 '14 at 00:56
  • 2
    This was helpful in that it made me "see" that my classes closing bracket was above the start of my method. I'm just starting to use Visual Studio 2017 and it automatically adds both brackets, specifically adds the closing bracket right next to the opening - which I'm not used to (after years of using VS 2008) and didn't even notice I wasn't writing methods inside the class! – Doreen Jan 30 '18 at 16:44
  • For me the solution was to remove and add the tables back to EF model first – tfa May 02 '19 at 08:59