2016-01-28 24 views
-1

我一遍又一遍地看了一遍,我似乎無法弄清楚問題所在。在查看了一些常見問題後,人們添加了額外的大括號或者只是忘記了一個,但是我已經仔細查看了它,並且似乎找不到我弄亂的地方。什麼導致這個錯誤,爲什麼會發生?它的顯示上線120錯誤和105爲什麼Visual Studio會說這是「類型或名稱空間定義,或期望的文件結束」?

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; 
      } 
     } 
    } 
}   
+0

提供[MCVE]總是個好主意 - 它通常要麼解決問題,要麼至少表現出很好的效果。在當前狀態下,您的帖子很可能會因爲「印刷錯誤」而關閉(而這種「代碼牆」帖子顯示對其他時間的低度尊重 - 但這很少會阻止任何人提問/回答)。 –

回答

0

你的最後兩個方法需要低於一個大括號,目前他們是FixedUpdate()方法內。

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; 
} 
+0

非常感謝!這解決了這個問題。 – Airwarfare

0

您的FixedUpdate()方法沒有足夠的括號。

0

方法public int indexHolder(int i), public void playerTimeVars(object source, ElapsedEventArgs e)被放置在private void FixedUpdate()方法中,這是該錯誤的來源。將它們放在FixedUpdate之外,它應該修復錯誤

相關問題