- Home /
I cannot figure out what my error is...
Hi, I am a beginner at programming in C#, and I need help with finding the issue that I am having right now. Here is the code below:
 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
 
     private const string typeName = "UniqueGameName";
     private const string gameName = "RoomName";
     
     private void StartServer()
     {
         Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
         MasterServer.RegisterHost(typeName, gameName);
     }
     
     void OnServerInitialized()
     {
         Debug.Log("Server Initializied");
     }
     
     void OnGUI()
     {
         if (!Network.isClient && !Network.isServer)
         {
             if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
                 StartServer();
         }
     }
 
     private HostData[] hostList;
     
     private void RefreshHostList()
     {
         MasterServer.RequestHostList(typeName);
     }
     
     void OnMasterServerEvent(MasterServerEvent msEvent)
     {
         if (msEvent == MasterServerEvent.HostListReceived)
             hostList = MasterServer.PollHostList();
     }
 
     private void JoinServer(HostData hostData)
     {
         Network.Connect(hostData);
     }
     
     void OnConnectedToServer()
     {
         Debug.Log("Server Joined");
     }
 
     void OnGUI()
     {
         if (!Network.isClient && !Network.isServer)
         {
             if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
                 StartServer();
             
             if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
                 RefreshHostList();
             
             if (hostList != null)
             {
                 for (int i = 0; i < hostList.Length; i++)
                 {
                     if (GUI.Button(new Rect(400, 100 + (110 * i), 300, 100), hostList[i].gameName))
                         JoinServer(hostList[i]);
                 }
             }
         }
     }
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 
And my error says:
Assets/NetworkManager.cs(52,14): error CS0111: A member 'NetworkManager.OnGUI()' is already defined. Rename this member or use different parameter types
PLEASE HELP!
Thanks! -Eric N.
Answer by richyrich · Jan 19, 2015 at 03:45 AM
You need to remove this code:
  void OnGUI()
  {
      if (!Network.isClient && !Network.isServer)
      {
          if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
              StartServer();
      }
  }
It is a subsection of the other function by the same name.
The error message is telling you that you cannot have two methods by the same name
Note: Technically you can have two functions with the same name, but they must have different parameters.
Your answer
 
 
             Follow this Question
Related Questions
help my code has error CS8205 :parsing error how can I fix? 2 Answers
Help me It keeps giving me error Unknown identifier 'Fire' 1 Answer
C# Error help ( error CS0023 The `!’ operator cannot be applied to operand of type `string’ ) ??? 1 Answer
InvalidCastException when Instantiating with photon (PUN) 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                