PLEASE HELP Convert JavaScript to C#.

Hello, i have a small problem in my project and i want some help. I have a script with is written in JavaScript and i want to convert it to C#. I have tried this online tool but it didn’t work. http://www.m2h.nl/files/js_to_c.php Can anyone convert this script to c# for me please?

Thank you in advance.

 import System.IO;

private var latestVersionString = "randomText";
var thisVersionFloat : float = 1.0;
var dropBoxLatestVersionTXT = "https://www.dropbox.com/s/???????????????/version.txt?dl=1";
function Start () {

   var www : WWW = new WWW(dropBoxLatestVersionTXT);
   yield www;
     latestVersionString = www.text;
    
    var latestVersionFloat : float = 3.14159265358979f;
   
    latestVersionFloat = float.Parse(latestVersionString);

    if(latestVersionFloat==thisVersionFloat) Debug.Log("You have the latest version of the game");
    if(latestVersionFloat>thisVersionFloat) Debug.Log("You have outdated version of the game");

}

Not sure exactly what you are trying to accomplish. But here is a basic conversion to C#! I have not tested it, but it is error free! Hope this gets you moving in the right direction!

using UnityEngine;
using System.Collections;
using System.IO;


public class DropboxChecker : MonoBehaviour {

   private string latestVersion = "randomText";
   public float thisVersion = 1.0f;
   public string latestVersionTXT = "https://www.dropbox.com/s/???????????????/version.txt?dl=1";
   private string www;
   private float latestVersionFloat;
   
   void Start ()
   {
       www = new WWW(latestVersionTXT).ToString();

       latestVersion = www;

       latestVersionFloat = 3.14159265358979f;

       latestVersionFloat = float.Parse (latestVersion);

       if (latestVersionFloat == thisVersion)
       {
           Debug.Log ("You have the latest version of the game.");       
       }
       else
       {
           Debug.Log ("You have an outdated version of the game.");
       }

   }


}

You usually yield the WWW object in a coroutine or poll the isDone property. The ToString() method does not what you believe it does here. :stuck_out_tongue:

@
Why is it even written in UnityScript? The C# documentation for the WWW clearly shows the basic usage, you could have looked that up instead of waiting for replies on the forums.

Nevertheless, first some notes:
You are better off using either a string, an integral type or a custom type to represent the version number. While floats do work, I would simply not recommend them.

A string would totally remove all the parsing and you’d be left with the pure equality test. An integer would not require to use approximation to eliminate tiny inaccuracies for the comparison.

Back to your version, you should generally use the TryParse method instead of the normal Parse method to prevent superfluous exceptions.
Like mentioned above, floats should be compared with approximation rather than the bit-wise equality test, unless you really want to rely on bit-wise equality.
Last but not least, a request to external resources is always a candidate for uncontrollable failure. You want to check for errors first, using the request .error property.

A rough translation might look something like this, which I’ve quickly tested with a file instead of a website.
(I kept the floats, if you want to follow the advice about the version number’s type, it’ll be easy to change)

using System.Collections;
using UnityEngine;

// replace of CLASS_NAME with your file name
public class CLASS_NAME : MonoBehaviour
{
    [SerializeField]
    private float _currentVersion = 1.0f; // I recommend to use a different type

    [SerializeField]
    private string _dropboxURL = @"YOUR_URL";

    private IEnumerator Start()
    {
        var request = new WWW(_dropboxURL);
        yield return request;
     
        if (!string.IsNullOrEmpty(request.error))
        {
            Debug.LogErrorFormat("The following error occured during the WWW request: {0}", request.error);
        }
        else
        {
            var latestVersion = -1f;
            if (float.TryParse(request.text, out latestVersion))
            {
                var isUpToDate = Mathf.Approximately(_currentVersion, latestVersion);
                Debug.LogFormat("Your version is {0}.", isUpToDate ? "up to date" : "outdated");
            }
            else
            {
                Debug.LogErrorFormat("Could not parse the version number. The response was: {0}", request.text);
            }
        }
    }
}