I’ve been defeated here regarding my ability to problem-solve… So here I am. First I’ll post my code, and then ill give context so you don’t have to read everything.
var DeviceInfo = {
// Function to get user agent string
GetUserAgent: function() {
return navigator.userAgent;
},
// Function to get screen width
GetScreenWidth: function() {
return screen.width;
},
}
autoAddDeps(DeviceInfo,'GetUserAgent')
autoAddDeps(DeviceInfo,'GetScreenWidth')
mergeInto(LibraryManager.library, DeviceInfo);
using UnityEngine;
using TMPro;
using System.Runtime.InteropServices;
public class DeviceInfo : MonoBehaviour
{
public TextMeshProUGUI userAgentText; // Reference to TextMeshPro Text object for user agent
public TextMeshProUGUI screenWidthText; // Reference to TextMeshPro Text object for screen width
// Import JavaScript plug-in functions
[DllImport("__Internal")]
private static extern string GetUserAgent();
[DllImport("__Internal")]
private static extern int GetScreenWidth();
void Start()
{
// Call JavaScript plug-in functions to retrieve device and browser information
string userAgent = GetUserAgent();
int screenWidth = GetScreenWidth()
;
// Update TextMeshPro Text objects with retrieved information
userAgentText.text = "User Agent: " + userAgent;
screenWidthText.text = "Screen Width: " + screenWidth;
}
}
I was working on a Device Feedback project for WebGL. The project will run a Unity WebGL project in the web browser. I started by creating my unity asset folders, then moved to my next step by creating a .jslib File, where I used Visual Studios to make a textile that I just changed to .jslib and saved it right into the PlugIn directory I made in my asset folder and where I then used the unity inspector to set the Platform Settings (But, didn’t tamper with any of the other settings which is one thing I’m hoping to get advice on). Then I made the c# script. After this, I decided id just set everything up in the editor and press play before i build the project, however, I always get a EntryPointNotFoundException:
assembly: type: member: (null)
DeviceInfo.Start () error, so I just built the project and had some success with my GetScreenWidth(); printing to the screen. My problem is, the userAgent Did not. Does anyone know where I might have done something wrong, or what I might need to understand to solve this problem, i am currently looking up information on wasm, but today I was aggressively trying to cover Emscriten docs, and I have no clue what to do or change regarding getting this string to print.