- Home /
Using Text file with .JS code written on it in webplayer?
Hi Unity Coders ?:-)
I would like to have a text input field next to a compiled webplayer game, where the player can write some lines of a function, and then the player can start the webplayer and it will import his code as something the game can read.
just for easy code for example:
function equation(){
var form = Mathf.Min(Mathf.Abs(x-Mathf.Floor(x+0.5)),Mathf.Abs(z-Mathf.Floor(z+0.5)));
return form;
}
It the task possible using an addon/dll/unitylibrary?
Answer by Eric5h5 · May 07, 2013 at 09:39 PM
You don't need any add-ons; you can use the eval() function to run strings as code. Note that you must turn off #pragma strict for eval() to work. So it doesn't work on platforms that enforce #pragma strict, like iOS.
Oh cool, Thankyou. do i have to use .Net's runtime for example System.IO classes you wrote in another thread? that's so cool i wish to make a mesh generator where people can decide the math topologies they walk in and maybe even add monsters :)
You can't use System.IO
in a webplayer, since Unity doesn't allow external file access in that case.
i have to use just this function on any string:
Application.ExternalEval
and do i have to do additional processing to make lines into a paragraph? i.e.:
var fileLines : List.;
function ReadFile() {
var sr = Application.ExternalEval("whatever.txt");
fileLines = sr.ReadToEnd().Split("\n"[0]).ToList();
sr.Close();
}
var wholeFileText = String.Join("\n", fileLines.ToArray());
Your answer
Follow this Question
Related Questions
Executing code from a text file and writing changes to it 1 Answer
how do i change text size? 0 Answers
Text Animation not playing 0 Answers
How can I change textmesh to a random text snippet? 1 Answer
GUIText Help 1 Answer