“名称空间不能直接包含诸如字段或方法之类的成员". [英] "A namespace cannot directly contain members such as fields or methods"

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

问题描述

我正在尝试使用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天全站免登陆