I am pretty good with C# but when it comes to loops, I am lost. Be it while, for or any other that may exist I have no idea how to use them. I have translated the UnityScript code given on this page but this loop is giving me the only error from the whole file.
C# Translation
public class ServerCore : MonoBehaviour
{
int maxClients = 10;
int listenPort = 2943;
NetworkPlayer p;
void StartServer ()
{
Network.InitializeServer(maxClients, listenPort, false);
}
void StopServer ()
{
Network.Disconnect();
}
void OnGUI()
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
GUILayout.Label("Network server is not running.");
if (GUILayout.Button("Start Server"))
{
StartServer();
}
}
else
{
if (Network.peerType == NetworkPeerType.Connecting)
GUILayout.Label("Network server is starting up...");
else
{
GUILayout.Label("Network server is running.");
showServerInformation();
showClientInformation();
}
if (GUILayout.Button("Stop Server"))
{
StopServer();
}
}
}
void showClientInformation()
{
GUILayout.Label("Clients: " + Network.connections.Length + "/" + maxClients);
for(p in Network.connections) // Where I'm getting the error
{
GUILayout.Label(" Player from ip/port: " + p.ipAddress + "/" + p.port);
}
}
void showServerInformation()
{
GUILayout.Label("IP: " + Network.player.ipAddress + " Port: " + Network.player.port);
}
}
Original
var listenPort = 25000;
var maxClients = 5;
function startServer() {
Network.InitializeServer(maxClients, listenPort, false);
}
function stopServer() {
Network.Disconnect();
}
function OnGUI ()
{
if (Network.peerType == NetworkPeerType.Disconnected) {
GUILayout.Label("Network server is not running.");
if (GUILayout.Button ("Start Server"))
{
startServer();
}
}
else {
if (Network.peerType == NetworkPeerType.Connecting)
GUILayout.Label("Network server is starting up...");
else {
GUILayout.Label("Network server is running.");
showServerInformation();
showClientInformation();
}
if (GUILayout.Button ("Stop Server"))
{
stopServer();
}
}
}
function showClientInformation() {
GUILayout.Label("Clients: " + Network.connections.Length + "/" + maxClients);
for(var p: NetworkPlayer in Network.connections) {
GUILayout.Label(" Player from ip/port: " + p.ipAddress + "/" + p.port);
}
}
function showServerInformation() {
GUILayout.Label("IP: " + Network.player.ipAddress + " Port: " + Network.player.port);
}