- Home /
Question by
flyte · Sep 21, 2013 at 07:09 AM ·
c#javascripttranslate
Help With Java Script - C#
Could Someone please help by translating this into c#
function Awake() {
MasterServer.RequestHostList("MadBubbleSmashGame");
}
function OnGUI() {
var data : HostData[] = MasterServer.PollHostList();
// Go through all the hosts in the host list
for (var element in data)
{
GUILayout.BeginHorizontal();
var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
GUILayout.Label(name);
GUILayout.Space(5);
var hostInfo;
hostInfo = "[";
for (var host in element.ip)
hostInfo = hostInfo + host + ":" + element.port + " ";
hostInfo = hostInfo + "]";
GUILayout.Label(hostInfo);
GUILayout.Space(5);
GUILayout.Label(element.comment);
GUILayout.Space(5);
GUILayout.FlexibleSpace();
if (GUILayout.Button("Connect"))
{
// Connect to HostData struct, internally the correct method is used (GUID when using NAT).
Network.Connect(element);
}
GUILayout.EndHorizontal();
}
}
Thank you in advance.
Comment
Answer by getyour411 · Sep 21, 2013 at 07:20 AM
Add this to top
using UnityEngine;
using System.Collections;
Change function to void
Change var to a type reference Use this:
Your answer
![](https://koobas.hobune.stream/wayback/20220613114539im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem Javascript to C# 3 Answers
translate javascript for loop to C# 2 Answers
Weird warnings after translating javascript to C# 2 Answers
Distribute terrain in zones 3 Answers
How to make this line work in C#? 1 Answer