“命名空间不能直接包含成员,例如字段或方法"; [英] "A namespace cannot directly contain members such as fields or methods"

查看:56
本文介绍了“命名空间不能直接包含成员,例如字段或方法";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Reflexil 将此代码用于 NET.reflector.我试图用这个替换代码:

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"

我认为这是 Unity 代码.我没有那么有经验.谁能帮我解决这个问题?或者告诉我该怎么做?谢谢!

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

推荐答案

您显示的代码段似乎与错误没有直接关系.

The snippet you're showing doesn't seem to be directly responsible for 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) }.

这篇关于“命名空间不能直接包含成员,例如字段或方法";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆