- Home /
C# to java translation
Hi Can anyone translate this code to javascript for me?
I'm trying to get the script so when a url is typed into a textfield it recognises it and makes it into a hyper linke. I'd really appreciate some help with this one.
using UnityEngine;
public class Example : MonoBehaviour
{
string url = "http://www.unity3d.com";
void OnGUI()
{
url = GUILayout.TextField(url, GUILayout.Width(200));
if (IsLink(url)) // Is it a link?
{
// Then show the submit button...
if (GUILayout.Button("Submit", GUILayout.Width(200)))
{
// do something with url...
}
}
}
bool IsLink(string text)
{
if (text.StartsWith("http://") || text.StartsWith("www"))
return true;
else
return false;
}
}
I apologize if I seemed abrupt there, truth is I did try but have never touched C#, seemed easier to post the original code than the hash job I made. Thanks so much for your help too, It's well appreciated. I'm pretty new to forums as it is and It takes a bit of getting used to. What can I do to sort out my code highlighting? I don't see the problem.
All the best
Answer by Bunny83 · Aug 10, 2011 at 10:17 PM
That's quite easy, but you shouldn't just ask for someone to write the script for your. Try it yourself and if your have a "real" question / problem come here. Also watch your code highlighting.
var url = "http://www.unity3d.com";
function OnGUI()
{
url = GUILayout.TextField(url, GUILayout.Width(200));
if (IsLink(url)) // Is it a link?
{
// Then show the submit button...
if (GUILayout.Button("Submit", GUILayout.Width(200)))
{
// do something with url...
}
}
}
function IsLink(text : String) : boolean
{
if (text.StartsWith("http://") || text.StartsWith("www"))
return true;
else
return false;
}
Answer by zarfishan · May 24, 2012 at 07:56 AM
you can convert you C# code to java using this free tool C# to java converter available online. its a cloud App so no need to install or download it just upload your code and it will be converter to java instantly.
That is not going to fly with Unity as Java isn't the same as JavaScript - which really should be called UnityScript to not confuse even further.
The main topic title does say java though, looks like they just didn't want to read the rest of the question post before answering.
Your answer
Follow this Question
Related Questions
About "translating" js into C# 1 Answer
Translate Unity-scripts to uScript 1 Answer
java to C# conversion 1 Answer
Translate code from C# to Javascript 1 Answer
Converting Variable to C# 1 Answer