Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda