I’m not the most code-savvy guy around these parts so pardon me if my question sounds stupid but: does Unet work with javascript/unityscript? I knew how to use the old network system fairly well with javascript, however since it’s going to be eventualy replaced by Unet, I decided to take a look at it… and didn’t find much in term of documentation for Unet in Javascript (most of it is written for C#).
I’ve tried to decypher the C# examples, and so far I managed to do the basic such as getting your server online, have someone join, spawn some players, etc (most of it was relatively similar to the old system anyway). All in Javascript. However I wanted to try the new @SyncVar and @ClientRpc attributes… and that’s where the problems start: the new attributes don’t seem to be doing anything? Yes the objects have a network identity component. But when I try to modify a variable that follows a @SyncVar with my server, the client doesn’t seem to receive the changes. Same for @ClientRpc.
At this point I’m guessing I’m just too green at this and simply don’t get how the new system works and I should read some more about it. But just in case I’d like to know if the issue isn’t simply that javascript isn’t currently supported, or poorly? If so, are there known workarounds?
Okay so, I guess I may not have been quite clear, or maybe people think I’m just a rambling fool. But I actually don’t know what’s up and would like some help.
As an example I coded a simple counter that is changed by the server, and synced with a client.
in C# it works perfectly:
using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking; using System.Collections; public class synctest : NetworkBehaviour { [SyncVar] public float counter = 0; void Update () { transform.GetComponent().text = counter.ToString(); if (transform.GetComponent().isServer) counter = counter+1 ; } }
However it doesn’t in Javascript:
import UnityEngine.Networking; import UnityEngine.UI; @SyncVar var counter : float; function Update() { transform.GetComponent(Text).text = counter.ToString(); if (transform.GetComponent(NetworkIdentity).isServer) counter +=1 ; }
I’m guessing I’m doing something horribly wrong (I’m not a real coder) but I would love to be told so by someone that could help me understand this :3 Thanks.
Edit: from the scripting manual “Using Javascript every script automatically derives from MonoBehaviour. When using C# or Boo you have to explicitly derive from MonoBehaviour.” so I guess that’s my issue, somehow I’d need my javascript scripts to derive from NetworkBehaviour, if that’s even possible?