Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

can't see javascript function

Discussion in 'Scripting' started by chubbspet, May 30, 2011.

  1. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    Hi there gus

    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
     
  2. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    anyone?
     
  3. Marrrk

    Marrrk

    Joined:
    Mar 21, 2011
    Posts:
    1,032
  4. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    Hi Marrk

    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

    Code (csharp):
    1. void Start()
    2.     {
    3.         MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
    4.  
    5.         sc.Language = "JScript";
    6.         string testexp = "Math.sqrt(81)";
    7.         var result = sc.Eval(testexp);
    8.  
    9.         Debug.Log(result.ToString());
    10.     }
    I really hope this can help someone else since this whole Javascript thing was a nightmare for me...
     
  5. lzblue

    lzblue

    Joined:
    Nov 3, 2015
    Posts:
    1
    Hi,

    May I know which file did you copy to the Plugins folder?
    Is it Interop.MSScriptControl.dll?
     
  6. Yuafa

    Yuafa

    Joined:
    Oct 17, 2016
    Posts:
    5
    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.