- Home /
Question by
blacksuit_films · Aug 10, 2011 at 04:05 PM ·
textfieldhyperlinks
Type in hyperlink to GUI
Hi
I've created a GUI.textfield where a user can post a message but so far they can only type in text. is there a way for them to paste in a hyperlink so that the GUI recognizes it as one?
Cheers
Comment
Best Answer
Answer by Statement · Aug 10, 2011 at 04:31 PM
C#
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;
}
}
JS
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(string text) : boolean
{
if (text.StartsWith("http://") || text.StartsWith("www"))
return true;
else
return false;
}
}
Oh sorry, completely forgot to mention I'm using Javascript. Is there a way to translate this?
$$anonymous$$y bad.
Your answer
Follow this Question
Related Questions
android textfield problem 1 Answer
Replace nonalphanumeric on textfield with regex, javascript 1 Answer
GUILayout.TextField doesn't accept inputs 1 Answer
How to save info and display in a textfield 1 Answer
TextField Font size 3 Answers