0
using UnityEngine;

using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

public string IP = "192.168.0.8";
    public int Port = "25001";

    void OnGUI()
    {

        if(Network.peerType == NetworkPeerType.Disconnected)
        {

            if (GUI.Button(new Rect(100,100,100,25),"Join Existing Server"))
            {

            Network.Connect(Ip,Port);   

            }



            if (GUI.Button(new Rect(100,125,100,25),"Create New Server"))
            {

            Network.InitializeServer(10,Port);
                //First Number Above next to port in perenthisies is number of allowed clients / 1x Server (# of players allowed to join game.)

            }

            else 
            {

            if(Network.peerType == NetworkPeerType.Client)  
                {


                    GUI.Label(new Rect(100,100,100,25),"Client");
                    if(GUI.Button (new Rect(100,125,100,25),"Disconnect"))
                    {

                        Network.Disconnect(250);


                    }


                }
                if(Network.peerType == NetworkPeerType.Server)
                {

                    GUI.Label(new Rect(100,100,100,25),"Server");
                    GUI.Label(new Rect(100,125,100,25),"Connections: " + Network.connections.Length);

                    if(GUI.Button (new Rect(100,125,100,25),"Disconnect"))
                    {

                        Network.Disconnect(250);

                    }
                }
            }
        }
    }
}

That is my code however it is generating the following errors that I for some reason can not find a way to rectify:

  1. Can not implicitly convert type 'string' to 'int'

Any help regarding this would be appreciated

thank you

1 Answer 1

1

While declaring the port declare it as

public int port = 25001;

This is because, we use "" only for declaring strings and string cannot be converted to integer implicitly. Hope this helps you. Anything else just post it here.

Sign up to request clarification or add additional context in comments.

5 Comments

Mention the errors and we shall try to help you out. also tell us the line where you can see more errors..
1. ip does not exist in current context 2. the best overloaded match for unityengine.network.connect(string,int') has some invalid arguments. 3. #1 cannot convert 'object' expression to string AND unityengine.Initializeserver is obselete?
The lines are as follows: 1. 19,29 2. 19,21 3. 19,21 4. 28,21
Replace public string IP = "192.168.0.8"; public int Port = "25001"; with public static string IP = "192.168.0.8"; public static int Port = "25001";
sorry my mistake it should be public static string IP = "192.168.0.8"; public static int Port = 25001;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.