“A namespace cannot directly contain members such as fields or methods” in Net.Reflector [closed]

旧城冷巷雨未停 提交于 2019-11-26 11:24:14

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/21175781/a-namespace-cannot-directly-contain-members-such-as-fields-or-methods-in-net-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!