Search Unity

How to call Javascript from Unity without .jslib ?

Discussion in 'Web' started by fastgamedev, Sep 1, 2018.

  1. fastgamedev

    fastgamedev

    Joined:
    Mar 27, 2014
    Posts:
    79
    My index.html page includes analytics.js that is hosted remotely. It has a javascript function
    StringReturnValueFunction()
    How do I call this function from Unity? The following code doesn't work because analytics.js in not a .jslib plugin:

    Code (csharp):
    1.  
    2.   public class A : MonoBehaviour {
    3.     [DllImport ("__Internal")]
    4.     private static extern string StringReturnValueFunction ();
    5.  
    6.     //////////////////////////////////////////////
    7.     void Start() {
    8.       Debug.Log (StringReturnValueFunction ());
    9.     }
    10.   }
    11.  
     
  2. MidgardDev

    MidgardDev

    Joined:
    Dec 11, 2012
    Posts:
    47
    I don't think you can anymore. In the past you could have just called Application.ExternalCall or ExternalEval, but all of that is now marked as insecure and won't work on production games.

    You have to use a jslib plugin
     
  3. fastgamedev

    fastgamedev

    Joined:
    Mar 27, 2014
    Posts:
    79
    Well, I can of course write jslib middleware, but I was hoping there is a direct way.
     
  4. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    pearhaps UnityWebRequest.
    i use this to run php-scripts.