- Home /
can anybody convert this script to js? (C#)
hi, can anybody convert this script to js? i need this? c# script:
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, 5300);
}
if (gui.Button("host"))
{
Network.InitializeServer(10, 5300, false);
}
}
}
}
Answer by Julien-Lynge · Oct 18, 2011 at 04:30 PM
In response to your question
can anybody convert this script to js? (C#)
The answer is: Yes! You can!
Unity's javascript and C# implementations are very similar. Here are a couple of resources to get you started:
http://col000r.blogspot.com/2009/12/unity-making-switch-from-javascript-to.html
http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
You can also check out this answer for a possible way to directly convert the script:
http://answers.unity3d.com/questions/21573/converting-code-from-javascript-to-c.html
BTW: this seems to be such a common question that I've created a blog post I can just send people to in the future:
http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/
If anyone has any other good links for resources on converting, let me know and I'll add them to the list.
Here's some links I found useful in converting between C# and JS :
http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/
Your answer

Follow this Question
Related Questions
Send hero to attack builds (js) 0 Answers
Referencing booleans from settings 1 Answer
StreamReader returning incorrect results 0 Answers
On carachterspawn level load error? 0 Answers
Save Timer HighScore 1 Answer