I’m trying to use the eval function from a javascript file in C#, but I just can’t seem to “see” the javascript file. I have placed the myParser.js file in a Plugins folder inside the Assets folder. I have also made the function in the javascript file static, but no luck. I’m trying to access the myParser class by declaring a int and then try to populate it with
float testFloat = … and then I can’t see my javascript class
Can anyone please shed some light on this urgent problem, thanks
I tried that but with no luck and then found a very nice alternative solution just now after searching the whole net this whole morning. What I did was this:
I added a reference to my project (Microsoft Script Control 1.0)
Copied this file into my Plugins folder
Then I tried this and it is working so nicely
void Start()
{
MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
sc.Language = "JScript";
string testexp = "Math.sqrt(81)";
var result = sc.Eval(testexp);
Debug.Log(result.ToString());
}
I really hope this can help someone else since this whole Javascript thing was a nightmare for me…
yes, it is Interop.MSScriptControl.dll
it is necessary to change Api Compatibility Level to .NET 4.x(Unity2019.3)
then change Target Platform to Windows, Architecture to x86
After build, It will work.
In editor, it can’t work.