Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

help C# NetworkLevelLoad script has errors

Discussion in 'Scripting' started by Digzzy, Mar 12, 2015.

  1. Digzzy

    Digzzy

    Joined:
    Jan 25, 2015
    Posts:
    4
    this is my script and some thing is wrong and i cant find whats wrong :(
    errors i have are:
    1.error CS1519: Unexpected symbol `[' in class, struct, or interface member declaration
    2.error CS8025: Parsing error
    3.error CS0101: The namespace `global::' already contains a definition for `MYCLASSNAME'
    thanks for helping me out

    EDIT:
    1. error fixed
    2. error fixed
    3. error fixed thanks fluzing
    and there is a new error NetworkLevelLoad.cs(4,1): error CS8025: Parsing error i edited the code

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. {
    6.     {
    7.     public class NetworkLevelLoad : MonoBehaviour
    8.     string[] supportedNetworkLevels = [ "mylevel" ];
    9.     string disconnectedLevel = "loader";
    10.  
    11.     private int lastLevelPrefix= 0;
    12.  
    13.     void  Awake (){
    14.         DontDestroyOnLoad(this);
    15.         networkView.group = 1;
    16.         Application.LoadLevel(disconnectedLevel);
    17.     }
    18.  
    19.     void  OnGUI (){
    20.         if (Network.peerType != NetworkPeerType.Disconnected)
    21.     {
    22.         GUILayout.BeginArea( new Rect(0, Screen.height - 30, Screen.width, 30));
    23.         GUILayout.BeginHorizontal();
    24.        
    25.         foreach(var level in supportedNetworkLevels)
    26.         {
    27.             if (GUILayout.Button(level))
    28.             {
    29.                 Network.RemoveRPCsInGroup(0);
    30.                 Network.RemoveRPCsInGroup(1);
    31.                 networkView.RPC( "LoadLevel", RPCMode.AllBuffered, level, lastLevelPrefix + 1);
    32.             }
    33.         }
    34.         GUILayout.FlexibleSpace();
    35.         GUILayout.EndHorizontal();
    36.         GUILayout.EndArea();
    37.     }
    38. }
    39.  
    40.     [RPC]
    41.     void  LoadLevel ( string level ,   int levelPrefix  ){
    42.         Debug.Log("Loading level " + level + " with prefix " + levelPrefix);
    43.         lastLevelPrefix = levelPrefix;
    44.  
    45.         Network.SetSendingEnabled(0, false);  
    46.  
    47.         Network.isMessageQueueRunning = false;
    48.        
    49.         Network.SetLevelPrefix(levelPrefix);
    50.         Application.LoadLevel(level);
    51.         yield return 0;
    52.         yield return 0;
    53.  
    54.         Network.isMessageQueueRunning = true;
    55.  
    56.         Network.SetSendingEnabled(0, true);
    57.  
    58.         for (var go in FindObjectsOfType(typeof(GameObject)))
    59.             go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);  
    60.         }
    61.  
    62.         void  OnDisconnectedFromServer (){
    63.             Application.LoadLevel(disconnectedLevel);
    64.     }
    65.  
    66.     @script RequireComponent(NetworkView)
    67.  
    68.   }
    69.  
    70. }  
    71. }
     
    Last edited: Mar 13, 2015
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    You probably have 2 scripts with the same name. Change the name of the script and the class to something else.
     
  3. Digzzy

    Digzzy

    Joined:
    Jan 25, 2015
    Posts:
    4
    helped but a new error come:NetworkLevelLoad.cs(4,1): error CS8025: Parsing error
    (i edited the code a bit :) ) sry english is bad :D
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. {
    5.     {
    6.     public class NetworkLevelLoad : MonoBehaviour
    7.     string[] supportedNetworkLevels = [ "mylevel" ];
    8.     string disconnectedLevel = "loader";
    9.  
    10.     private int lastLevelPrefix= 0;
    11.  
    12.     void  Awake (){
    13.         DontDestroyOnLoad(this);
    14.         networkView.group = 1;
    15.         Application.LoadLevel(disconnectedLevel);
    16.     }
    17.  
    18.     void  OnGUI (){
    19.         if (Network.peerType != NetworkPeerType.Disconnected)
    20.     {
    21.         GUILayout.BeginArea( new Rect(0, Screen.height - 30, Screen.width, 30));
    22.         GUILayout.BeginHorizontal();
    23.      
    24.         foreach(var level in supportedNetworkLevels)
    25.         {
    26.             if (GUILayout.Button(level))
    27.             {
    28.                 Network.RemoveRPCsInGroup(0);
    29.                 Network.RemoveRPCsInGroup(1);
    30.                 networkView.RPC( "LoadLevel", RPCMode.AllBuffered, level, lastLevelPrefix + 1);
    31.             }
    32.         }
    33.         GUILayout.FlexibleSpace();
    34.         GUILayout.EndHorizontal();
    35.         GUILayout.EndArea();
    36.     }
    37. }
    38.  
    39.     [RPC]
    40.     void  LoadLevel ( string level ,   int levelPrefix  ){
    41.         Debug.Log("Loading level " + level + " with prefix " + levelPrefix);
    42.         lastLevelPrefix = levelPrefix;
    43.  
    44.         Network.SetSendingEnabled(0, false);  
    45.  
    46.         Network.isMessageQueueRunning = false;
    47.      
    48.         Network.SetLevelPrefix(levelPrefix);
    49.         Application.LoadLevel(level);
    50.         yield return 0;
    51.         yield return 0;
    52.  
    53.         Network.isMessageQueueRunning = true;
    54.  
    55.         Network.SetSendingEnabled(0, true);
    56.  
    57.         for (var go in FindObjectsOfType(typeof(GameObject)))
    58.             go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);  
    59.         }
    60.  
    61.         void  OnDisconnectedFromServer (){
    62.             Application.LoadLevel(disconnectedLevel);
    63.     }
    64.  
    65.     @script RequireComponent(NetworkView)
    66.  
    67.   }
    68.  
    69. }  
     
    Last edited: Mar 13, 2015