Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Unity jslib import in c# script don't work?

I started using jslib plugins with unity and following the documentation I created this jslib file:

var plugin = {

    Autologin: function () {
        var sessionData = [
            sessionStorage.getItem("USERNAME"),
            sessionStorage.getItem("PASSWORD")
        ];
        return sessionData;
    },

    GetTargetParams: function () {

        function findGetParameter(parameterName) {
            var result = null,
                tmp = [];
            var items = location.search.substr(1).split("&");
            for (var index = 0; index < items.length; index++) {
                tmp = items[index].split("=");
                if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
            }
            return result;
        }

        return findGetParameter("platform");


    },
};

mergeInto(LibraryManager.library, plugin);

I use the jslib functions in the c# file like that:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.UIElements;
using UnityEngine.SceneManagement;
using System;
using System.Runtime.InteropServices;

public class InitHandler : MonoBehaviour
{

    public bool isMobile = false;
    [DllImport("__Internal")]
    private static extern string[] Autologin();

    [DllImport("__Internal")]
    private static extern string GetTargetParams();

    // Start is called before the first frame update
    void Start()
    {
        try
        {
            switch (GetTargetParams())
            {
                case "mobile":
                    isMobile = true;
                    break;
                case "pc":
                    isMobile = false;
                    break;
            }
        }
        catch { Debug.LogWarning("Target checking will not be executed cause it's not a webgl build."); }
        try
        {
            StartCoroutine(StartAUTOLogin(Autologin()[0], Autologin()[1]));
        }
        catch { Debug.LogWarning("Autologin will not be executed cause it's not a webgl build."); }

        SceneManager.LoadScene("Login");

    }

    // Update is called once per frame
    void Update()
    {
        
    }

    IEnumerator StartAUTOLogin(string User, string Password)
    {
        WWWForm form = new WWWForm();
        form.AddField("Username", User);
        form.AddField("Password", Password);

    }
}

When I build this i don't get ANY compiler errors. My question is now why the functions I import don't work in a webgl build. So when I pass the parameter platform=mobile it's not setting isMobile to true. I'm beginner with jslibs so don't be hard please and don't critisize my english. I'm not native speaker.

Hope you can help me, Franz Fischer

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!