- Home /
How to rewrite C# to Javacript in Unity - writing a game with server based on nodejs with socket
I have one problem and I can't solve. I can't rewrite this code from c# to Javacsript.
using UnityEngine;
using System.Collections.Generic;
using SocketIO;
public class Network : MonoBehaviour {
static SocketIOComponent socket;
void Start()
{
socket = GetComponent<SocketIOComponent>();
socket.On("open", OnConnected);
}
void OnConnected(SocketIOEvent e)
{
Debug.Log("connected");
socket.Emit("move");
}
}
I'm reading tutorial on pluralsight about creating game in Unity - https://app.pluralsight.com/library/courses/unity-multiplayer-game-dev-node-2454/table-of-contents
Can anyone help with it? I don't into this languages and I can't do this - if anyone can rewrite it to me I will be very glad, because I will be have a "template" and I will can rewrite other files.
Yes, I read topics and articles (including this forum)about prescribing and converting c# to Javascript, but I can't really do this.
Answer by Eric5h5 · Sep 25, 2016 at 07:56 PM
import System.Collections.Generic;
import SocketIO;
private static var socket : SocketIOComponent;
function Start()
{
socket = GetComponent.<SocketIOComponent>();
socket.On("open", OnConnected);
}
function OnConnected(e : SocketIOEvent)
{
Debug.Log("connected");
socket.Emit("move");
}
Then you have a different question, since the above is a direct translation of the C# you posted to Unityscript.
What do you mean by "not working"? It's the one-to-one translation to UnityScript. If the C# version works, the UnityScript translation will also work. The script you posted in your question and the UnityScript translation Eric posted does exactly the same.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093454im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Rewriting script from JavaScript to C# 1 Answer
Multiple Cars not working 1 Answer
C# to UnityScript conversion help. 0 Answers
Problem Javascript to C# 3 Answers