C# 为什么VisualStudio说这是;类型或命名空间定义,或应为文件结尾“;?

C# 为什么VisualStudio说这是;类型或命名空间定义,或应为文件结尾“;?,c#,C#,我已经看了一遍又一遍,我似乎不明白问题是什么。在查找了一些常见的问题后,人们只是添加了额外的支架或只是忘记了一个支架,但我查看了它,似乎找不到我把事情搞砸的地方。是什么导致了这个错误,为什么会发生?它显示了第120行和第105行的错误 using UnityEngine; using Rocket.Core.Plugins; using Rocket.Core.Logging; using Rocket.Unturned.Events; using Rocket.Unturned.Player;

我已经看了一遍又一遍,我似乎不明白问题是什么。在查找了一些常见的问题后,人们只是添加了额外的支架或只是忘记了一个支架,但我查看了它,似乎找不到我把事情搞砸的地方。是什么导致了这个错误,为什么会发生?它显示了第120行和第105行的错误

using UnityEngine;
using Rocket.Core.Plugins;
using Rocket.Core.Logging;
using Rocket.Unturned.Events;
using Rocket.Unturned.Player;
using System.Collections.Generic;
using Rocket.Unturned;
using System;
using System.Timers;

namespace VipTeleport
{
    public class VipTeleport : RocketPlugin
    {
        public static VipTeleport Instance;
        public Vector3 DeathPos;
        public UnturnedPlayer movePlayer;
        public bool canTeleport = false;
        public int timerT = 0;
        public List<string> players = new List<string>();
        public List<PlayerFinder> playerVars = new List<PlayerFinder>();
        public PlayerFinder playerInfo;
        public string steamId;
        public int[] playerTimer = new int[24];
        public int[] playerSteamID = new int[24];
        public bool[] playersCanTeleport = new bool[24];
        public int index;


        protected override void Load()
        {
            VipTeleport.Instance = this;
            //Just console logs for the plugin in RocketApi on unturneds server console
            Logger.LogWarning("##################################");
            Logger.LogWarning("#Vip Teleport Loaded Sucessfully!#");
            Logger.LogWarning("##################################");
            Logger.LogWarning("#         Version  V.1.0         #");
            Logger.LogWarning("##################################");
        }

        protected override void Unload()
        {

        }



        private void FixedUpdate()
        {
            U.Events.OnPlayerConnected += (UnturnedPlayer player) =>
            {
                int addTo = Convert.ToInt32(player.CSteamID);
                foreach (int f in playerSteamID)
                {
                    if (f == 0)
                    {
                        playerSteamID[f] = addTo;
                        foreach (int i in playerTimer)
                        {
                            playerTimer[f] = 0;
                            break;
                        }
                        foreach (bool t in playersCanTeleport)
                        {
                            playersCanTeleport[f] = false;
                        }
                        break;
                    }
                }
            };
            //Listener for player Death
            UnturnedPlayerEvents.OnPlayerDead += (UnturnedPlayer player, Vector3 Vector3) =>
            {
                int localSteamID = Convert.ToInt32(player.CSteamID);
                foreach (int i in playerSteamID)
                {
                    if (i == localSteamID)
                    {
                        index = i;
                        playerTimer[index] = 120;
                        break;
                    }
                }

                System.Timers.Timer aTimer = new System.Timers.Timer();
                aTimer.Elapsed += new ElapsedEventHandler(playerTimeVars);
                aTimer.Interval = playerTimer[index];
                aTimer.Enabled = true;

                if ((playerTimer[index] <= 120) && (playerInfo.timerT > 0))
                {
                    playerInfo.canTeleport = true;
                }
                else
                {
                    playerInfo.canTeleport = false;
                    playerInfo.timerT = 0;
                }
            };


            U.Events.OnPlayerDisconnected += (UnturnedPlayer player) =>
            {

            };


            public int indexHolder(int i)
            {
                return i;
            }

            public void playerTimeVars(object source, ElapsedEventArgs e)
            {
                int localIndex = indexHolder(index);
                playerTimer[localIndex] = 0;
            }
        }
    }
}         
使用UnityEngine;
使用Rocket.Core.Plugins;
使用Rocket.Core.Logging;
使用Rocket.Unturned.Events;
使用Rocket.Unturned.Player;
使用System.Collections.Generic;
使用火箭。未翻转;
使用制度;
使用系统计时器;
命名空间VipTeleport
{
公共级VipTeleport:RocketPlugin
{
公共静态VipTeleport实例;
公共向量3死亡位置;
公共未翻转播放器移动播放器;
public bool canTeleport=false;
公共int timerT=0;
公共列表玩家=新列表();
public List playerVars=新列表();
公共播放者提示播放者信息;
公共字符串序列号;
public int[]playerTimer=新int[24];
public int[]playerSteamID=新int[24];
公共bool[]playersCanTeleport=新bool[24];
公共整数指数;
受保护的覆盖无效负载()
{
VipTeleport.Instance=this;
//只需unturneds服务器控制台上RocketApi中插件的控制台日志
Logger.LogWarning(日志警告);
Logger.LogWarning(“#Vip传送成功加载!#”);
Logger.LogWarning(日志警告);
Logger.LogWarning(“#版本V.1.0#”);
Logger.LogWarning(日志警告);
}
受保护的覆盖无效卸载()
{
}
私有void FixedUpdate()
{
U.Events.OnPlayerConnected+=(未翻转的播放器)=>
{
int addTo=Convert.ToInt32(player.CSteamID);
foreach(playerSteamID中的int f)
{
如果(f==0)
{
playerSteamID[f]=addTo;
foreach(playerTimer中的int i)
{
playerTimer[f]=0;
打破
}
foreach(playersCanTeleport中的bool t)
{
playersCanTeleport[f]=假;
}
打破
}
}
};
//玩家死亡的聆听者
UnturnedPlayerEvents.OnPlayerDead+=(UnturnedPlayerPlayer,Vector3 Vector3)=>
{
int localstreamid=Convert.ToInt32(player.CSteamID);
foreach(playerSteamID中的int i)
{
if(i==localstreamid)
{
指数=i;
playerTimer[index]=120;
打破
}
}
System.Timers.Timer aTimer=新的System.Timers.Timer();
aTimer.appead+=新的ElapsedEventHandler(playerTimeVars);
aTimer.Interval=playerTimer[index];
aTimer.Enabled=true;
if((playerTimer[index]0))
{
playerInfo.canTeleport=true;
}
其他的
{
playerInfo.canTeleport=false;
playerInfo.timerT=0;
}
};
U.Events.OnPlayerDisconnected+=(未翻转的玩家)=>
{
};
公共int索引文件夹(int i)
{
返回i;
}
public void playerTimeVars(对象源,ElapsedEventArgs e)
{
int localIndex=indexHolder(索引);
playerTimer[localIndex]=0;
}
}
}
}         

您的最后两个方法需要位于大括号下方,目前它们位于
fixeupdate()方法中

private void FixedUpdate()
{
...

    U.Events.OnPlayerDisconnected += (UnturnedPlayer player) =>
    {
    };
}

public int indexHolder(int i)
{
    return i;
}

public void playerTimeVars(object source, ElapsedEventArgs e)
{     
    int localIndex = indexHolder(index);
    playerTimer[localIndex] = 0;
}

您的
FixedUpdate()
方法没有足够的括号。

方法
public int indexHolder(int i)、public void playerTimeVars(object source,ElapsedEventArgs e)
放在
private void FixedUpdate()方法中,该方法是此错误的根源。将它们放在
FixedUpdate
之外,它将修复错误

非常感谢!这就解决了问题。提供它总是一个好主意——它通常要么解决问题,要么至少表现出良好的努力。在当前状态下,您的帖子可能会被关闭为“排版错误”(这种“代码墙”帖子显示出对他人时间的不尊重——但这很少阻止任何人提问/回答)。