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);
}
}
}
}
}
}
这是我的代码但是它产生了以下错误,我出于某种原因无法找到纠正方法:
对此有任何帮助将不胜感激
谢谢
答案 0 :(得分:1)
声明端口时将其声明为
public int port = 25001;
这是因为,我们只使用“”来声明字符串,并且字符串不能隐式转换为整数。希望这对你有所帮助。还有别的东西只是贴在这里。