- Home /
Translate code from C# to Javascript
Can someone please help translate this script? I've got this script from someone else, but I can only read unityjava. I've tryed something, but it's not working yet...
GameMenu.cs
using UnityEngine; using gui = UnityEngine.GUILayout;
public class GameMenu : MonoBehaviour { public GameObject PlayerPrefab; string ip = "127.0.0.1";
public void CreatePlayer()
{
connected = true;
var g = (GameObject)Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 1);
g.camera.enabled = true;
camera.enabled = false;
}
void OnDisconnectedFromServer()
{
connected = false;
}
void OnPlayerDisconnected(NetworkPlayer pl)
{
Network.DestroyPlayerObjects(pl);
}
void OnConnectedToServer()
{
CreatePlayer();
}
void OnServerInitialized()
{
CreatePlayer();
}
bool connected;
void OnGUI()
{
if (!connected)
{
ip = gui.TextField(ip);
if (gui.Button("connect"))
{
Network.Connect(ip, 1990);
}
if (gui.Button("host"))
{
Network.InitializeServer(10, 1990, false);
}
}
}
}
Here's some links I found useful in converting between C# / JS :
http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
Answer by dylanfries · Jun 29, 2012 at 01:03 PM
The only things that should really be different are the function headers and the stuff at the beginning. Try just creating a blank js file and see i you can translate it out. You might be surprised. Also defining variables will be different. All the unity specific stuff should be exactly the same.
Your answer
![](https://koobas.hobune.stream/wayback/20220613073451im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
About "translating" js into C# 1 Answer
Help| Convert a javascript to C# 1 Answer
Translation music script from c# to js 1 Answer
Distribute terrain in zones 3 Answers
C# to java translation 2 Answers